<<<<excel and VB lookup

T

Tenerife Alan

I am using Excel 2003 and Visual Basic 6.3

VLOOKUP works fine in a worksheet but I am having trouble when I try to
invoke it in VB.

My code is

head = VLookup(code, "\icodes", 2)

Where code is a VB variable and "\icodes" is a named range on a worksheet.

I get the error message Function not defined.
 
D

Dave Peterson

In VBA, I'd use:

Dim res as variant 'it could be an error
dim myVal as long 'double, string ????
dim LookUpRng as range

set lookuprng = worksheets("Sheet2").range("a:b")

myval = 21234

res = application.vlookup(myval, lookuprng, 2, false)

if iserror(res) then
msgbox "not found" 'like #n/a error
else
msgbox res
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top