Validar datos con VLOOKUP

yoguibubu

New Member
Joined
Feb 19, 2002
Messages
6
Como puedo validar un dato en un Userform que no lo encuentra VLookup?

Tengo puesto esto y no controla el error:

Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
ValorChequeo = Application.VLookup(Val(UserForm1.TextBox2.Value), Worksheets("Productos").Range("B6", "D179"), 3, 0)
If Err.Number = 2042 Then
MsgBox "Este producto no existe"
Cancel = True
Exit Sub
End If
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Bueno, traté con dos TextBox en un UserForm, en el que actualizo el TextBox2 con el valor buscado de TextBox1.

Usé este código:

Code:
If IsError(Application.VLookup(TextBox1.Value, Range("A1:B4"), 2, 0)) And TextBox1 <> "" Then
    MsgBox "No Existe"
    TextBox1 = ""
    Cancel = True
Else
    TextBox2 = Application.VLookup(TextBox1.Value, Range("A1:B4"), 2, 0)
End If

Y me funcionó, así que creo que el problema está en la definición del Rango de búsqueda.

Que pasa si en vez de

Worksheets("Productos").Range("B6", "D179")

usa

Worksheets("Productos").Range("B6:D179")

?
 
Upvote 0
Juan Pablo:
Funciona correctamente con el
If IsError .....
Lo del Rango con , o con ; lo admite de las dos formas.
Saludos
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,291
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top