This is my code for finding a value in excel.if Paint Shop
is not found then it will get the method range of object _global failed
. I\'m new to excel m
To handle this scenario, try this:
Dim myvalue
On Error Resume Next
myvalue = WorksheetFunction.Match("Paint Shop", Range(col & x, col & y), 0)
On Error Goto 0
If Not IsEmpty(myvalue) Then
paint = myvalue
Else
paint = 2000
End If
You incorporate Error Handling
routine OERN
to check if the worksheet function fails.
If it does, myvalue
will not be initialized and you can check if it is empty or not.
Also take note that i declared myvalue
as Variant
data type.
Reason is for IsEmpty
to evaluate it correctly.