ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   <<<<excel and VB lookup (https://www.excelbanter.com/excel-discussion-misc-queries/218496-excel-vbulletin-lookup.html)

Tenerife Alan

<<<<excel and VB lookup
 
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.
--
Tenerife Alan

Barb Reinhardt

<<<<excel and VB lookup
 
Have you tried

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

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Tenerife Alan" wrote:

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.
--
Tenerife Alan


Dave Peterson

<<<<excel and VB lookup
 
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



Tenerife Alan wrote:

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.
--
Tenerife Alan


--

Dave Peterson


All times are GMT +1. The time now is 10:15 AM.

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