vlookup of file that file name changes week to week

nlange41

New Member
Joined
Dec 3, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a report that I run every week and save with the file name and current date. Part of the process is to open the previous week's file and do a Vlookup to pull in a column from the previous week's report. I'm trying to write in the macro the Vlookup instead of doing it manually. I know how to link it to where the report is saved, however, because the file name changes every week, I'm having trouble with the file name in the macro. I have the previous week's date in B1. I have tried below but get a syntax error. I have B1 formatted to
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(@C[-1],'[Ref Numbers "&B1&".xlsx]Sheet1'!C1:C2,2,FALSE)"
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I have a report that I run every week and save with the file name and current date. Part of the process is to open the previous week's file and do a Vlookup to pull in a column from the previous week's report. I'm trying to write in the macro the Vlookup instead of doing it manually. I know how to link it to where the report is saved, however, because the file name changes every week, I'm having trouble with the file name in the macro. I have the previous week's date in B1. I have tried below but get a syntax error. I have B1 formatted to
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(@C[-1],'[Ref Numbers "&B1&".xlsx]Sheet1'!C1:C2,2,FALSE)"
I hit enter on accident.
I have B1 formatted to 26-Nov-21 and file named the same.
 
Upvote 0

Forum statistics

Threads
1,215,636
Messages
6,125,961
Members
449,276
Latest member
surendra75

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