Vlookup in Visual Basics

  • Thread starter Thread starter Sarah
  • Start date Start date
S

Sarah

What is the exact code to use the Vlookup function in a
visual basics custom macro? I need to be able to use this
in a loop that will have at least 2 index variables.
 
Some versions of XL have a hard time with the WorksheetFunction
object and VLookup, so you should use the Application object instead:

Dim result As Variant

result = Application.VLookup(LValue, LRange, LIndex, True)

where LValue, LRange, LIndex are varialbes holding your lookup value
lookup range and index, respectively. Change True to False for an
exact match (result will = Error 2042 if no match is found).
 
Thanks J E! Making all the parameters variables works very well

----- J.E. McGimpsey wrote: ----

Some versions of XL have a hard time with the WorksheetFunction
object and VLookup, so you should use the Application object instead

Dim result As Varian

result = Application.VLookup(LValue, LRange, LIndex, True

where LValue, LRange, LIndex are varialbes holding your lookup value
lookup range and index, respectively. Change True to False for an
exact match (result will = Error 2042 if no match is found)
 
Back
Top