Solved

Issues with vlookup in Excel

Posted on 2013-01-18
5
285 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
Outlook Free & Paid Tools
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now