how to use a VLOOKUP function in a VBA code?

S

Sunil

Hi
am a novice in excel...i have a excel sheet with 2 columns with around 10000
records.i have placed a button in the excel sheet and on clicking the button
it should find all the values in the first column which doesnt have a match
in the second column.for that i can use VLOOKUP function.but i dont know how
to use that one.
Can any one help me?

Thanks in advance....

With Regds

Sunil.T
 
S

Sunil

Hi,

i tried ..but am getting some errors...it will be very helpful for me if
u send me the syntax regarding my req.Thanks in advance

With regds
Sunil.T
 
M

mangesh_yadav

Hi Sunil,

Here's an example:

Private Sub CommandButton1_Click()

Set myRng = Worksheets("Sheet1").Range("A1:B10")
myLookup = 4

myValue = WorksheetFunction.VLookup(myLookup, myRng, 2)

End Sub


The table is A1:B10.
myLookup is the lookup_value which would be in column A. myValue is the
value corresponding to the myLookup as returned by the above formula.
2 is the column index number which tells the lookup to look for the
result in the second column of the table A1:B10 i.e. column B


Mangesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top