Using Built in Functions in VBA Code

  • Thread starter Thread starter Chris Parker
  • Start date Start date
C

Chris Parker

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
 
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
 
Back
Top