Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default External file VBA Vlookup code

dim Range_Lookup as range
dim lookup_row_value as string
dim found_value as variant

lookup_row_value = "Test"

'tables.xls must be open
set range_lookup _
= workbooks("tables.xls").worksheets("sheet1").range ("a1:c100")

found_value = application.vlookup(lookup_row_value, range_lookup, 2, false)

if iserror(found_value) then
'n/a would have been returned
else
'no error
end if

David Travers wrote:

I have a function in Excel on a worksheet to go and lookup the value in a
table in another file e.g

=VLOOKUP("TEST",'C:\Blairs[tables.xls]Sheet1'!$A$1:$C$100,2)

and this works fine.

However I'm trying to replicate the same in a VBA macro to create a static
document without any functions and cannot get the routine to work e.g

lookup_row_value = "TEST"
range_lookup = "'C:\[tables.xls]Sheet1'!$A$1:$C$100"
found_value = Application.WorksheetFunction.VLookup(lookup_row_v alue,
Range(range_lookup), 2, False)

Any ideas what I'm doing wrong and how I can fix it. Keep getting a Range
error.

Cheers


--

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 to an external file Lee Crew Excel Discussion (Misc queries) 8 September 21st 09 04:01 PM
Vlookup in external file Tami Excel Worksheet Functions 2 October 8th 08 09:55 PM
Code to select 'Disable Macro' when opening an EXTERNAL FILE G rumpy O ld D uffer Excel Programming 1 March 22nd 05 05:32 PM
How do I use vlookup to point to an external file that changes nam Aschaney Excel Worksheet Functions 3 January 20th 05 08:01 PM
Use macro code from external xls file Angus Comber[_2_] Excel Programming 1 November 10th 03 11:10 PM


All times are GMT +1. The time now is 09:20 AM.

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"