Error in excel vba, using . offset, to search for products in a spreadsheet

Asked

Viewed 35 times

-2

Hello, I’m trying to learn Excel vba to help my father in his company, I use the version of excel 2016, in the code I built following the course, it was time to enter the product code, it shows the manufacturer, number and part name, But he only recognizes the first line of the spreadsheet where the products are, I hope you help me, I thank you already! Code:

Private Sub Btnconsultar_Click()

 Dim EmpFound As Range
 
 With Range("Códigos_valv")
 
 Set EmpFound = .Find(Me.Txt_cod.Value)
 
 If EmpFound Is Nothing Then
    
    MsgBox "Válvula não encontrada", vbCritical, "Consultar válvula"
    
    Me.Txt_cod.Value = ""
    
    Else
    
    With Range(EmpFound.Address)
    
    Me.Txt_numero = .Offset(0, 1)
    Me.Txt_nomeval = .Offset(0, 2)
    Me.Txt_fabri = .Offset(0, 3)
    
    
    On Error Resume Next
    Me.Ifoto1.Picture = LoadPicture("C:\Users\Usuario\Desktop\RRG Type\para converter\Imagens para cadastro\Imagens válvulas\" & EmpFound & ".jpg")
    
    
    On Error GoTo 0
    
    End With
 End If
End With

 Set EmpFound = Nothing   
 
End Sub

1 answer

0

Hello,

Please, could you provide more details of the reason for using the VBA in this case? I ask, because as it comes to the search for a product for a unique code, the use of =PROCV(VLOOKUP) in the spreadsheet would bring all the information you need (if necessary, I show here how it could be applied).

Also, reading the code, there seems to be a need to load an image as well. This image would also need to be loaded via vba for some specific reason?

As soon as you can answer here, I can give a more concrete solution to your problem.

At you.,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.