MrExcel Publishing
Your One Stop for Excel Tips & Solutions


Posted by Roy on November 12, 2001 11:27 AM

Probably a silly question but can someone please tell me how i use vlookup within a macro.

ie how is it written when u want to use a formula

Posted by Denis on November 12, 2001 11:44 AM

go to insert\function , select lookup & reference
on the left hand side , vlookup on the right handside , then press ok & follow the instructions

Posted by Roy on November 12, 2001 12:17 PM

Sorry i wanted to know how to do this within a macro. ie in VBA

Sorry for the confusion

Posted by Barrie Davidson on November 12, 2001 1:37 PM

I assume you are assigning a lookup value to a variable. Use something like:

variable = Application.WorksheetFunction.VLookup(LookupValue, LookupRange, IndexNumber, 0)

To assign a lookup value to the variable named "variable". Where "LookupValue" is the value you are looking up, "LookupRange" is the range of data you are looking in to, "IndexNumber" is the number of columns over from a match, and "0" indicates an exact match is required.

Does this help you out?
BarrieBarrie Davidson