Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VLookup in a Macro

I am trying to write a macro that duplicates a data evaluation procedure
given to me from someone else. There are several steps requiring VLOOKUPs.
I have been told that I cannot run a VLOOKUP within a macro? Is this a true
statement. If I can do it, how?

--
Sincerely,
Beverly76
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default VLookup in a Macro

Hi

To use worksheet functions in VBA use this syntax:

Application.WorksheetFunction.VLOOKUP(lookup_value ,table_array,col_index_num,range_lookup)

BTW: It's not all worksheet functions which are available in VBA.

Regards,
Per

On 8 Sep., 20:48, Beverly76
wrote:
I am trying to write a macro that duplicates a data evaluation procedure
given to me from someone else. *There are several steps requiring VLOOKUPs. *
I have been told that I cannot run a VLOOKUP within a macro? *Is this a true
statement. *If I can do it, how?

--
Sincerely,
Beverly76


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VLookup in a Macro

VBA code will only do Exact matches using the VBA Find(). Bt you can call
the lokup worksheet functions (lookup, v lookup,hlookup) from VBA.

Excel 2003 : worksheetfunctions.vlookup(...)
Excel 2007 : application.vlookup(...)


"Beverly76" wrote:

I am trying to write a macro that duplicates a data evaluation procedure
given to me from someone else. There are several steps requiring VLOOKUPs.
I have been told that I cannot run a VLOOKUP within a macro? Is this a true
statement. If I can do it, how?

--
Sincerely,
Beverly76

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VLookup in a Macro

If you mean Range.Find, then you can tell excel to look for an exact match or
ignore the case. There are parms for that in that method.

And all newer versions of excel (xl97 and higher) can use either:

application.worksheetfunction.vlookup(...)
or
application.vlookup(...)

(I _think_ that .worksheetfunction was added with xl97. But it may have been
added with xl95.)

Joel wrote:

VBA code will only do Exact matches using the VBA Find(). Bt you can call
the lokup worksheet functions (lookup, v lookup,hlookup) from VBA.

Excel 2003 : worksheetfunctions.vlookup(...)
Excel 2007 : application.vlookup(...)

"Beverly76" wrote:

I am trying to write a macro that duplicates a data evaluation procedure
given to me from someone else. There are several steps requiring VLOOKUPs.
I have been told that I cannot run a VLOOKUP within a macro? Is this a true
statement. If I can do it, how?

--
Sincerely,
Beverly76


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VLookup in a Macro

Dim res as variant 'could be an error
dim myRng as range
dim myVal as variant 'or long or string or ...

with worksheets("sheet9999")
set myrng = .range("a:e") '5 columns
end with

myVal = worksheets("sheet8888").range("x77").value

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

if iserror(res) then
msgbox "Error, not found"
else
msgbox res
end if


Beverly76 wrote:

I am trying to write a macro that duplicates a data evaluation procedure
given to me from someone else. There are several steps requiring VLOOKUPs.
I have been told that I cannot run a VLOOKUP within a macro? Is this a true
statement. If I can do it, how?

--
Sincerely,
Beverly76


--

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 Macro? blucajun Excel Worksheet Functions 3 June 30th 08 09:54 PM
VLOOKUP Macro? blucajun Excel Worksheet Functions 0 June 27th 08 10:23 PM
VLOOKUP WITH MACRO yusuf Excel Programming 2 October 30th 07 08:21 AM
Vlookup in a macro cultgag[_3_] Excel Programming 4 February 14th 06 10:03 PM
Please help.. VLookup Macro richinlaf31[_5_] Excel Programming 1 August 4th 05 01:34 AM


All times are GMT +1. The time now is 04:25 PM.

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

About Us

"It's about Microsoft Excel"