Bom dia!!
Para uso do VLookup é necessário verificar o retorno #N/A
Veja um exemplo..
Private Sub TextBox1_Change()
On Error Resume Next
Ms = Application.WorksheetFunction.VLookup(Me.TextBox1.Value, Worksheets("Plan3").Range("A2:G5000"), 2, False)
On Error GoTo 0
If Ms <> "" Then MsgBox Ms
End Sub
Private Sub txtEan_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next 'Armadilha de Erros
If Len(txtEan.Text) >= 7 Then
form1 = WorksheetFunction.VLookup(Val(txtEan.Text), Worksheets("BD_Prod").Range("A1:D100000"), 2, 0)
form2 = WorksheetFunction.VLookup(Val(txtEan.Text), Worksheets("BD_Prod").Range("A1:D100000"), 3, 0)
form3 = WorksheetFunction.VLookup(Val(txtEan.Text), Worksheets("BD_Prod").Range("A1:D100000"), 4, 0)
If Err.Number = 0 Then ' <---
txtCod.Text = form1
txtDesc.Text = form2
txtVlrUnit.Text = form3
Me.txtEan.BackColor = vbWhite
Else
MsgBox "Por favor entre com o EAN correto", vbOKOnly, "EAN não encontrado"
txtEan.SetFocus
txtEan.Text = ""
End If
End Sub
Att
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 07/11/2016 5:25 am