ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Built in Functions in VBA Code (https://www.excelbanter.com/excel-programming/271818-using-built-functions-vba-code.html)

Chris Parker

Using Built in Functions in VBA Code
 
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

Tom Ogilvy

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







All times are GMT +1. The time now is 05:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com