View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Richard Buttrey Richard Buttrey is offline
external usenet poster
 
Posts: 296
Default How can I trap this Vlookup error in a VBA macro

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
__________________________