-
VBA - function Vlookup
Hi everyone,
In my module i pretend search a value corresponding to a variable a.
But when i run the code variable h are incorrect, because apeear error 2042 and the suppose is appear a number.
My code is:
Code:
Sub Macro3()
Dim j As Variant
Dim a As Variant
Dim h As Variant 'variavel de teste
Set Model = Workbooks("AtrasosTotal.xlsm").Worksheets("Model")
lastRowZModel = Model.Cells(Model.Rows.Count, "A").End(xlUp).Row
a = 1600104092
Sheets("Model").Select
Set b = Range("A2:O" & lastRowZModel)
h = Application.VLookup(a, b, 12, False)
End Sub
How can I resolve this problem
-
Wrap VBA code in Code tags !
Code:
Sub M_snb()
sn=Workbooks("AtrasosTotal.xlsm").sheets("Model").usedrange
for j=1 to ubound(sn)
if sn(j,1)=1600104092 then exit for
next
msgbox sn(j,12)
End sub
-
google error 2042.
What is the reason for VBA error 2042? - Quora
add an error handler to your code.
-
Nice! It's working, but isn't efficient, because i have many lines for execute the cicle FOR.
You have any sugestion?