referencing a workbook that has a dynamic name

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
195
Office Version
  1. 365
I'm having a problem with my V-lookup code--when I reference the exact worksheet name, it works fine. But, the workbookname will actually change month to month. All of my commands to open the workbook using the dynamic workbook name are effective. Example:

The following 2 lines code work:
Message = "Enter the quarter for billing purposes. (Ex: 2Q05)"
FileQuarter = InputBox(Message)
Workbooks.Open Filename:="I:\Wcm\Public\Mgmtfees\" & FileQuarter & "MDLCdata.xls"

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-3],[2Q05MDLCdata.xls]Sheet1!R3C3:R500C9),7,FALSE)"

But when I try to make the name dynamic, the following code does not work:
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-3],[FileQuarter & "MDLCdata.xls"]Sheet1!R3C3:R500C9),7,FALSE)"
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this and Good Luck:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-3],[" & FileQuarter & "MDLCdata.xls]Sheet1!R3C3:R500C9),7,FALSE)"
 
Upvote 0
if you kick your code into single step mode, what do you get when you print the above expression in the immediate window? Good Luck!
 
Upvote 0
Well, by stepping away from it for a little bit, and coming back, I noticed that I didn't type it exactly as you had typed the formula. It now works!!! Thank you!
 
Upvote 0

Forum statistics

Threads
1,218,626
Messages
6,143,582
Members
450,494
Latest member
GolfNut39

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top