Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ignore N/A in macro 1

Status
Not open for further replies.

wayneryeven

Technical User
May 21, 2004
101
GB
Hey all
I have a macro that looks at a cells contents then executes code based on that content:

If Range("V2") Like "Test*" Then
' Run Test Code
Else
' Do Nothing
End If

As you can see if the cell contains Test it will execute code otherwise it ignores it. Now it so happens that each cell in Column V is based on a lookup. The code is fine as long as V has a value. If it encounters an N/A error (lookup failed) then my code fails with a:

Run time error 13
Type mismatch

Anyone any ideas on how i could get round this? Unfortuantly column V will have to remain a lookup...

Many thanks, all suggestions welcomed.
 
Take a look at using a Worksheet function in your code. Although there is a ".IsNA" function available, you may be better served by using the ".IsText" function:
Code:
Dim V2IsLikeTest As Boolean
    
V2IsLikeTest = False
If (WorksheetFunction.IsText(Range("V2"))) Then V2IsLikeTest = (Range("V2") Like "Test*")

If (V2IsLikeTest) Then
    ' Run test code
Else
    ' Do nothing
End If
 
Hey Dave
Thanks for the heads up regarding IsNa- i have actually achieved a solution using this, albeit your solution is valid, a star none the less for your assitance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top