View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ardus Petus Ardus Petus is offline
external usenet poster
 
Posts: 718
Default How can I trap this Vlookup error in a VBA macro

Strange indeed. Get around with on error:

Sub test()
Dim i As Long
On Error Resume Next
i = WorksheetFunction.Match(9, Range("A1:A12"), 0)
On Error GoTo 0
If i = 0 Then MsgBox "Not Found"
End Sub

HTH
--
AP

"Richard Buttrey" a écrit dans le
message de ...
Hi,

I have a need to identify whether a Job Number appears in a specific
range, and take different actions in a mcaro dependent on whether it
is or isn't present.

As a function this would simply be

=If(Iserror( Vlookup(x,MyRange,1,false)),"This","That")

However I'm having difficulties building this into a macro using
Application.WorksheetFunction. I keep stumbling on the 'Unable to get
the Vlookup property of the Worksheet Function Class" where the job
number doesn't exist

I've also tried MyRange.Find(what:=JobNo, after ............etc.,
but get the 'Object Variable with Block Variable not set' error, where
the jobs doesn't exist.

How can I construct an

If "JobNo exists" Then
"This"
else
"That"
End If

test?


Usual TIA

__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________