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
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
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
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
See my post to your question in VBA Forum.
RE: Excel macro - Vlookup
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
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
Thanks for the input. It raises a few more questions regarding the WorksheetFunction issue, but that's what learning is all about!