#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default VLookUp in VBA

Using Excel 2003, is there a way to use the =Vlookup worksheet function in a
macro? (VBA code). I've tried

dim resultt as string
resultt=vlookup("02111","a1:ab545",3,false)

and all I get is a "sub or function not defined" message.

Thanks in advance for your help.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VLookUp in VBA

Dim Res as variant 'could be an error
dim myVal as variant 'string or long or double or ???
dim LookUpRng as range

with activesheet
set lookuprng = .range("a1:ab545")
end with

myVal = "02111" 'not 2111???

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

if iserror(res) then
msgbox "No match"
else
msgbox res
end if



PeterM wrote:

Using Excel 2003, is there a way to use the =Vlookup worksheet function in a
macro? (VBA code). I've tried

dim resultt as string
resultt=vlookup("02111","a1:ab545",3,false)

and all I get is a "sub or function not defined" message.

Thanks in advance for your help.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default VLookUp in VBA

thanks for responding

"02111" is in quotes because in the worksheet the value to be looked up is
number stored as a text string, therefore "02111"

but you've answered my question, got it to work....thank you for your help

"Dave Peterson" wrote:

Dim Res as variant 'could be an error
dim myVal as variant 'string or long or double or ???
dim LookUpRng as range

with activesheet
set lookuprng = .range("a1:ab545")
end with

myVal = "02111" 'not 2111???

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

if iserror(res) then
msgbox "No match"
else
msgbox res
end if



PeterM wrote:

Using Excel 2003, is there a way to use the =Vlookup worksheet function in a
macro? (VBA code). I've tried

dim resultt as string
resultt=vlookup("02111","a1:ab545",3,false)

and all I get is a "sub or function not defined" message.

Thanks in advance for your help.


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Vlookup -=VLOOKUP(F9,LookUp1!$A$2:$B$1504,2,FALSE) MikeR-Oz New Users to Excel 1 March 22nd 06 09:01 AM
IF(AND(val1=VLOOKUP( );val2>=VLOOKUP( );val2<=VLOOKUP( );VLOOKUP( Oso Excel Worksheet Functions 2 January 26th 05 06:56 AM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


All times are GMT +1. The time now is 11:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"