View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Using Built in Functions in VBA Code

I find leaving out the WorksheetFunction portion works better for me. Also,
when a #N/A would be returned if used in the worksheet (no find), if you
just use Application, you can test the return value with iserror. If you
use WorksheetFunction as a qualifier, you have to use Error trapping since
it raises a trappable error.

Dim Res As Variant
Res = _
Application.VLookup(123,Range("A1:B10"),2,False)
if iserror(res) then
msgbox "Not found"
else
msgbox "Valure returned is " & res
End if

Regards,
Tom Ogilvy


"Chip Pearson" wrote in message
...
Chris,

Try something like

Dim Res As Variant
Res =
Application.WorksheetFunction.VLookup(123,Range("A 1:B10"),2,False)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Chris Parker" wrote in message
om...
Hi I need some assistance.
Can somebody show my how to use say a vlookup function in my vba

code
, as opposed to using it on a worksheet. I've done this before

but
can't remember how

Something to do with application object ?

Thanks in anticipation

Chris