?
Solved

How to make an Excel VBA vlookup when the tables are on another workbook?

Posted on 2014-10-02
2
Medium Priority
?
9,285 Views
Last Modified: 2014-10-04
How would I go about making a macro that uses vlookup formulas when the tables are on another workbook?
If you look at the BHNRES-Unrecovered-Equipment-TEST VBA file on the 2nd tab it shows the results that I am looking for.
The macro I made is asking to open up the workbook where the tables are on...I do not want it to do this. Is there another to do this?

Thanks,
Jimi
BrightHouse-Item-Code-Reference.xlsx
BHNRES-Unrecovered-Equipment-1-59-TEST-V
0
Comment
Question by:Jimi Sherman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 2000 total points
ID: 40358667
It's easier to set up cross-workbook references when both files are open.  Once you create the VLOOKUP formulas correctly, Excel will retain the filepath of the referenced (and possibly closed) workbook in the formula.  Of course, if the source file is moved or deleted, this won't work.

So, the raw formulas in the "Example VBA Results" sheets should be (copied down):
C2: =VLOOKUP(A2,[BrightHouse_Item_Code_Reference.xlsx]Codes'!$A:$B,2,FALSE)
E2: =VLOOKUP(G2,[BrightHouse_Item_Code_Reference.xlsx]Codes'!$D:$E,2,FALSE)

If you wanted to create the formula without the source file ("BrightHouse_Item....") open, you would need to include the full drive:\filepath in front of the first square bracket, like so:
=VLOOKUP(A2,'C:\BrightHouseDirectory\Subdirectory\Subdir2\[BrightHouse_Item_Code_Reference.xlsx]Codes'!$D:$E,2,FALSE)
Also note the single apostrophe around the path, filename, and sheet name (needed because of spaces, but good practice).

===============
If you are trying to insert this in VBA, it's no different than inserting a regular formula, and since you have no quotation marks, that won't be an issue.  For example:
Range("C2").Formula = "=VLOOKUP(A2,[BrightHouse_Item_Code_Reference.xlsx]Codes'!$A:$B,2,FALSE)"

Open in new window

or with the full path,
Range("C2").Formula = "=VLOOKUP(A2,'C:\C:\BrightHouseDirectory\Subdirectory\Subdir2\[BrightHouse_Item_Code_Reference.xlsx]Codes'!$D:$E,2,FALSE)

Open in new window


Hope that helps,
Glenn
0
 

Author Closing Comment

by:Jimi Sherman
ID: 40361775
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question