Update Excel VLOOKUP based on newest file - excel

I have an excel file, automatically generated each morning with a generic name (Filename_YYYYMMDD).
Also I have an XLSM file that contains vlookup targeted to the above mentioned generic file.
In a macro, I would like to update the vlookup to point to the NEWEST file automatically created. Newest can mean either with the biggest date in the file name or the freshest creation date in the file properties. It should check either of the two parameters, change the file name in the vlookup formula and then automatically spread the formula to the whole column. The spreading part i can handle, but the date-change part I can not figure out.
Help?
Here is the vlookup:
=IFERROR(IF(H2=1;VLOOKUP(D2;'c:\path\[Filename_20130719.xlsx]Sheet1'!$B:$P;15;FALSE);G2);0)

If you know the date then you can use the replace method.
Something like:
Columns("A").Replace What:="20130719", Replacement:="20130720", LookAt:=xlPart
The catch is you always have to know the current date in the formula and the next date you want to replace.

Related

Is there a way to nest the TODAY() function into an external cell reference in Excel?

One of the daily repetitive tasks that my team handles requires using an excel template to format and upload rate indices to our system.
The 9 cells that contain the rates are currently set up as individual outside cell references. The format of the cell formulas are: ='S:\Ext1\Ext2[RATESHEET 02-02-2023.xlsx]RateName'!$C$7
The file being referenced in [RATESHEET 02-02-2023.xlsx] is updated every day with a new file and the current date. Right now, a member of the team has to go in daily and update each reference cell formula with today's date. I want this to update without going in to every cell.
I have three possibilities that seem plausible, but I can't seem to search correctly to figure out if any of these are possible in Excel.
Best case scenario, I would love to nest the function TEXT(TODAY(), "mm-dd-yyyy") into the reference formula and have each reference cell update with the daily date every time the file is opened.
Second best, I considered that all of the cells could reference a dummy cell that has the text/today function already in it.
Third best idea is to provide a user prompt to enter the date in that format, and have it update the cells from there.
Excel wizards, please let me know if there is any good way to accomplish this task.

excel format generated date (not hardcoded date)

I'm using closedxml to generate a excel file.
I'm mapping the cells directly in excel by creating a named range and inside of it reaching the items in the range by {{item.property}}, the range collection is added like a variable in the code.
The item I'm using has a Year property and a month property, the mapping in that excel cell is: {{item.Yr}}/{{item.Mon}}.
I would like Excel to format the value in the cell to mmm-yyyy (Jan-2020). Which it does if I directly write a date in the cell in Excel and presses Enter, but that's not what I want, I want it to format my generated value.
I've tried using the functions like =TEXT(date,format) or =DATEVALUE("1/1/2015").
But the problem is that I can't write directly "1/1/2015", I need to write something like DATEVALUE(1/{{item.Mon}}/{{item.Yr}} but Excel syntax doesn't allow this. Ofcourse I've also tried just the "format cell" to date on the cell, but doesn't work (only if I directly type a date and presses Enter)
I'm sorry for my crappy explanation. I hope someone understands what I mean and what I want to accomplish.
SOLVED
After 2 days banging my head against the wall, I found that If a variable is used in a formula, it needs to be escaped with "&" at the beginning:
&=Date({{item.Yr}},{{item.Mon}},1).

Concatenating File Path Excel

Lets say I have columns with dates on them.
The file path is something like this:
='U:\Report\[Date 042516.xls]Joe Smoe'!$C81
Where the '042516' is variable to each column. !$C81 is variable to each row in the original document.
How do I do this and pull up the respective numbers from the reports and dates?
I think I understand - so you have a column with numbers (042516,042517,042518, etc), and you want the formula to update that part of the path, as you drag down?
If your 042516 is in C1, you can use this:
=INDIRECT("'U:\Report\[Date "&C1&".xls]Joe Smoe'!$C81")
(Note the workbook being referenced, Date 042516.xls, must be open for Indirect to work.)

Alter file path based on cell reference

A short explanation; I have a large amount of reports in one folder, and they are all formatted the exact same way every time, except for the date in the file name (ex. Out of Stock Report WE 04.20.16.xlsx). In the workbook where I have my formula, I'm referencing a cell that has a date in it, and then using that date (DT$3 reference is a date) as an input for the last part of the file path, so that it goes to the correct file and looks up the file. I don't need any actual index/match or lookup formula, because these reports are all formatted the exact same way, so the needed value is always in the same cell on the same worksheet. Here is my formula that I'm getting a #REF error on:
='\\dhqshareddata\data\Supply_Chain\Planning\Strategic Planning - Forecasting\Out of Stock\All Reports\[Out of Stock Report WE "&TEXT(DT$3, ("MM.DD.YY"))&".xlsx]Category Report'!$C$5
This should be simple but I can't get it to work. Additionally, an indirect function won't do me any good because I'll have to open every single report and copy/paste values, for hundreds of reports.

Excel cell reference to other workbook using previous date for name

I need to reference data in my current worksheet (a daily log) to the previous day log (to show past day data).
I can do this in a fixed format using a direct reference to the other workbook. However I would really like to have it automatically reference cells in the previous day log. Thankfully the file names are formatted nicely "2016 01 January.xlsm" so referencing them using a formula shouldn't be hard.
I know I can build cell value that shows the previous day name using:
=text(today()-1, "yyyy dd Mmmm") & ".xlsm"
However, when I attempt to use this within the cell that should reference this sheet it seems my concatenation is broken in:
='[TEXT(TODAY()-1, "yyyy dd Mmmm") & ".xlsm"]Readings'!$J$14
I could easily debug the concatenation in Matlab, but sadly I'm not in that environment and I don't seem to understand how Excel works as well as I should.
Thanks in advance!
Ben
You simply need to prepend your formula with the INDIRECT command. INDIRECT tells excel that you are not explicitly referring to a particular location, but that you want to dynamically calculate a location, and then refer to that calculated spot. Assuming your file names are correct, this should be as easy as:
=INDIRECT(TEXT(TODAY()-1, "'\[yyyy dd mmmm") & ".xlsm]Readings'!J14")
To test out that it creates the file names correctly, consider putting the concatenation formula in a different cell, and then referring to that cell with INDIRECT. This will confirm for you that you aren't mispelling something etc.
*Edited as highlighted by Jeeped, to now properly calculate the file name instead of hardcoding as an explicit string of text.

Resources