Solved

Issues with vlookup in Excel

Posted on 2013-01-18
5
290 Views
Last Modified: 2013-01-18
I am trying to to a vlookup in another (opened) workbook.
I have done ths many times with great success.
Since yesterday, I have been working on this. The original sub and stuff were doing some pretty fancy stuff so, I kept trying to go for the basics.

Here is the code I am currently using:
Sub test()


For i = 1 To 20
MsgBox WorksheetFunction.VLookup(i, Workbooks("d:\desktop\testvlookup.xlsm").Sheets("Sheet1").Range("A:B"), 2, False)

Next

End Sub

Open in new window


I keep getting a subscript error.

If I try the same command from the same workbook (even different pages) with out the
           Workbooks("d:\desktop\testvlookup.xlsm")

Open in new window


 it will work.

I try and paste "d:\desktop\testvlookup.xlsm" in the run command and it says the book is open, so there is not a typo, and the file etc exists and is in fact open.
This is a very clean test workbook with "sheet1" having colA filled with numers 1-26 and column b filled with A-Z


What am I missing???
Office 2010. 32k  under Win7 64bit


Thanks
Bruce
0
Comment
Question by:Bruj
  • 3
5 Comments
 
LVL 26

Accepted Solution

by:
redmondb earned 250 total points
ID: 38795246
Hi, Bruce.

Drop the "d:\desktop\", i.e.
MsgBox WorksheetFunction.VLookup(i, Workbooks("testvlookup.xlsm").Sheets("Sheet1").Range("A:B"), 2, False)

Regards,
Brian.
0
 
LVL 39

Assisted Solution

by:nutsch
nutsch earned 250 total points
ID: 38795247
Try this instead

Workbooks("testvlookup.xlsm")

Open in new window


Since it's opened, the path is throwing things off.

Thomas
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38795252
Hi, Thomas.

Specifying the path wouldn't work for a closed file either.

Regards,
Brian.
0
 

Author Closing Comment

by:Bruj
ID: 38795267
DOH!!!!!
I have been working and working on this! I feel like an idiot.... Sum times ya just cant see the obvious!


Thanks guys!
Bruce
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38795335
Thanks, Bruce. We've all been there!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

789 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