Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Excel macro - Vlookup

Status
Not open for further replies.

bigb

Mechanical
Sep 17, 2002
12
0
0
US
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
 
Replies continue below

Recommended for you

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.

 
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
 
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.
 
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
Code:
Application.WorksheetFunction.FunctionName
, or
Code:
WorksheetFunction.FunctionName
, but will using the syntax
Code:
Application.FunctionName

Hope this clears things up. [smile]

Regards,
M. Smith
 
msmith,

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

 
Status
Not open for further replies.
Back
Top