Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup across workbooks

I'm using the following code to retrieve values from a second workbook
- the data is sorted in the second workbook. I've run the macro using
F8 and after a few successful retrievals within the loop, when a
target is not found in the second workbook the run time error 1004 is
reported.

Sheets("Hidden").Select
Range("j1").Select
For n = 1 To NumRows - 1
ActiveCell.Offset(1, 0).Select
ActiveCell.Formula =
Application.WorksheetFunction.VLookup(Range("i" & n + 1), _
Workbooks(mshare).Sheets("Sheet1").Range("$A:$Z"), 7,
False)
Next n

If I omit the false condition the macro runs through but on
examination, where no match has been found, a result is taken from
another row.

I'd like to return a "Not in second workbook" where a match is not
found. Is this possible?

I'd appreciate any assistance,

Bob Golightly
Nottingham, UK
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup across workbooks

That's the way application.worksheetfunction.vlookup() works.

But application.vlookup() will return an error:

Sheets("Hidden").Select
Range("j1").Select
For n = 1 To NumRows - 1
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Application.VLookup(Range("i" & n + 1), _
Workbooks(mshare).Sheets("Sheet1").Range("$A:$Z"), 7, False)
Next n

I changed your .formula to .value.

Did you want to plop a formula into that cell or just the results?

tiptoe wrote:

I'm using the following code to retrieve values from a second workbook
- the data is sorted in the second workbook. I've run the macro using
F8 and after a few successful retrievals within the loop, when a
target is not found in the second workbook the run time error 1004 is
reported.

Sheets("Hidden").Select
Range("j1").Select
For n = 1 To NumRows - 1
ActiveCell.Offset(1, 0).Select
ActiveCell.Formula =
Application.WorksheetFunction.VLookup(Range("i" & n + 1), _
Workbooks(mshare).Sheets("Sheet1").Range("$A:$Z"), 7,
False)
Next n

If I omit the false condition the macro runs through but on
examination, where no match has been found, a result is taken from
another row.

I'd like to return a "Not in second workbook" where a match is not
found. Is this possible?

I'd appreciate any assistance,

Bob Golightly
Nottingham, UK


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup across workbooks

On Feb 11, 7:41 pm, Dave Peterson wrote:
That's the way application.worksheetfunction.vlookup() works.

But application.vlookup() will return an error:

Sheets("Hidden").Select
Range("j1").Select
For n = 1 To NumRows - 1
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Application.VLookup(Range("i" & n + 1), _
Workbooks(mshare).Sheets("Sheet1").Range("$A:$Z"), 7, False)
Next n

I changed your .formula to .value.

Did you want to plop a formula into that cell or just the results?



tiptoe wrote:

I'm using the following code to retrieve values from a second workbook
- the data is sorted in the second workbook. I've run the macro using
F8 and after a few successful retrievals within the loop, when a
target is not found in the second workbook the run time error 1004 is
reported.


Sheets("Hidden").Select
Range("j1").Select
For n = 1 To NumRows - 1
ActiveCell.Offset(1, 0).Select
ActiveCell.Formula =
Application.WorksheetFunction.VLookup(Range("i" & n + 1), _
Workbooks(mshare).Sheets("Sheet1").Range("$A:$Z"), 7,
False)
Next n


If I omit the false condition the macro runs through but on
examination, where no match has been found, a result is taken from
another row.


I'd like to return a "Not in second workbook" where a match is not
found. Is this possible?


I'd appreciate any assistance,


Bob Golightly
Nottingham, UK


--

Dave Peterson


Dave,

Many thanks, it now runs returning #N/A in the cells without a match.
Can I be cheeky and ask you to suggest how I may replace the #N/A with
preferred test, e.g Not found ?

Bob




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 using different workbooks sam Excel Discussion (Misc queries) 4 October 2nd 09 02:15 AM
VLOOKUP 2 workbooks Holly Excel Discussion (Misc queries) 2 February 23rd 09 02:44 PM
Vlookup between two workbooks JodyGlenn Excel Worksheet Functions 0 May 17th 06 11:06 PM
VLookup across Workbooks? PH NEWS Excel Worksheet Functions 0 April 24th 06 03:43 PM
Help with Vlookup to several workbooks Les Stout[_2_] Excel Programming 3 November 2nd 05 07:45 PM


All times are GMT +1. The time now is 11:14 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"