referencing a workbook that has a dynamic name

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
158
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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

sbendbuckeye

Active Member
Joined
Nov 26, 2003
Messages
440
Try this and Good Luck:

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

sbendbuckeye

Active Member
Joined
Nov 26, 2003
Messages
440
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!
 

Rasberry

Board Regular
Joined
Aug 11, 2002
Messages
158
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!
 

Forum statistics

Threads
1,148,525
Messages
5,747,206
Members
424,068
Latest member
Salim khamis

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
Top