• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

vba code for vlookup

ganeshm

Member
Hi excel experts,

Is there a vba code for the following vlookup formula?

IFERROR(VLOOKUP(A2,[Book1.xlsx]Sheet1!$A$2:$C$8,3,FALSE), "").

Regards,
ganeshm
 
Hi Ganesh,

You can use this formula as it is in VBA
Code:
Range("A1").formula="=IFERROR(VLOOKUP(A2,[Book1.xlsx]Sheet1!$A$2:$C$8,3,FALSE), "")"
 
Hi, Abhijeet R. Joshi!
I updated your formula since embedded quotes should be double:
Range("A1").formula="=IFERROR(VLOOKUP(A2,[Book1.xlsx]Sheet1!$A$2:$C$8,3,FALSE), """")"
Regards!

Hi, gansehm!
Just in case you're looking after how to do that by code you could use the Application.WorksheetFunction.Vlookup method:
Code:
Something = Application.WorksheetFunction.VLookup(arg1, arg2, arg3[, arg4])
Same parameters as Excel function. Different notation.
Regards!
 
Hi, ganeshm!
Hope you solved it. Thanks for your feedback and welcome back whenever needed or wanted.
Regards!
 
Just a quick note.. :)

Most of the Application.Worksheet functions can be directly called from its parent member.. Application.

Code:
Something = Application.WorksheetFunction.VLookup(arg1, arg2, arg3[, arg4])
will work approx same as
Code:
Something = Application.VLookup(arg1, arg2, arg3[, arg4])

however, error handling mechanism is much better in case of Application.Member

Check here for more detail..
http://www.cpearson.com/Excel/CallingWorksheetFunctionsInVBA.aspx
 
@Debraj(ex-Roy)
Hi!
Nice tip, thanks, I didn't know it.
Regards!
PS: So it was because of it that the other day that damned code worked... o_O
 
@Marc L
Hi, buddy!
As you well said, I must have noticed, but I assume that I've always read faster and gone thru that parts without realizing the lack of the .WorksheetFunction chunk. :(
It's nice learning things every day. :)
Regards!
 
Back
Top