×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Excel macro - Vlookup

Excel macro - Vlookup

Excel macro - Vlookup

(OP)
Hi

I am having problem with this statement. Can you help me rewrite it?

If (IsNA(WorksheetFunction.VLookup(r, Range4, 2, False))) Then
        Range("X5").Offset(counter, 0).Value = "0A"
Else
    Range("X5").Offset(counter, 0).Value = "0B"
End If

Note: Range4 is  a lookup in a range in another sheet.


IsNA is giving problem says Sub or Function not defined.
I need to check if this vlookup returns a value else it should lookup some thing else.
Can you tell me what to do?
Thanks!!!!
BigB

RE: Excel macro - Vlookup

IsNA() is a worksheet function if I'm not mistaken, so try

If (WorksheetFunction.IsNA(WorksheetFunction.VLookup(r, Range4, 2, False))) Then
        Range("X5").Offset(counter, 0).Value = "0A"
Else
    Range("X5").Offset(counter, 0).Value = "0B"
End If


Seems like you already knew how to do that.

RE: Excel macro - Vlookup

(OP)
Hi
I tried Worksheetfunction.IsNA() but it does not work.

The problem here is because Vlookup does not return the value and hence there is is error. I am not able to capture it even though I tried your  method Could you suggest me another method/ code?

Thanks!!!!
BigB

RE: Excel macro - Vlookup

BigB,

See my post to your question in VBA Forum.

RE: Excel macro - Vlookup

BigB,

I'm not a VB user, but assuming that the syntax is similar in Excel formulas, shouldn't the IF statement have an ending parenthesis at the end of the line (and 1 less after 'False')?  If it is correct as you entered, please respond so that I'll know better as I venture into VB.

RE: Excel macro - Vlookup

suggest,

I'll answer for BigB since he doesn't have this thread marked for email notification and as it is somewhat old probably won't be monitoring it.

His IF statement is correct as written.  There are three open parentheses balanced by three close parens.  The outermost set actually serve no purpose and could be removed in this case.

The problem with BigB's function is related to a quirk in Excel VBA.  Some worksheet functions will not work if you use Application.WorksheetFunction.FunctionName, or WorksheetFunction.FunctionName, but will using the syntax Application.FunctionName

Hope this clears things up.  

Regards,
M. Smith

RE: Excel macro - Vlookup

msmith,

Thanks for the input.  It raises a few more questions regarding the WorksheetFunction issue, but that's what learning is all about!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close