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.
Related
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.
Background
The U.S. government releases a daily report I use for work. Recently, the government changed how they release their report. Instead of releasing the report as a text file, they are now releasing it as pdf. Unfortunately, this has affected how I pull information from the report. Previously, I pulled the information from the site as it was saved as a text file. Now, I download the pdf and convert it to an excel file.
I have 1 workbook that contains saved copies of the report on individual worksheets, e.g. April 30, April 29, April 28, etc. Unfortunately, due to the conversion, the information on each page can vary by a row or two, e.g. Information_A on April 30 worksheet could be on row 30 and on April 29 it could be on row 33.
On the first page of the workbook, I have a summary page which pulls key information from the previous page, e.g. Summary would pull information from the April 30 worksheet.
Problem
The problem now comes from how I pull the information from the excel file. Since the information is not on the same row, I thought the Index/Match method would be best. The formula I made is below. The reference name, Information_A, is in column A and the value I need from Information_A is in column P.
=(INDEX('April 30'!P:P,MATCH("Information_A",'April 30'!A:A,0)))
Since my worksheets constantly change I thought I would be able to pull the last worksheet name and then input it into the formula like so,
=(INDEX('[previous_sheet]'P:P,MATCH("Information_A",'[previous_sheet]'!A:A,0)))
So I tried to figure out how to pull the previous sheet name. I tried a few different ways and ended up using ChrisB's solution here.
I had saved the formula he provided (below) as PrevSheet_2
=IF( MATCH(wsName,wsNamesArray,0)-1 =0, ERROR.TYPE(7), INDEX(wsNamesArray,MATCH(wsName,wsNamesArray,0)+1))
Where, wsNamesArray and wsNameare as follows,
wsNamesArray: =RIGHT(GET.WORKBOOK(1),LEN(GET.WORKBOOK(1))-FIND("]",GET.WORKBOOK(1))) & T(NOW())
wsName: =MID(CELL("filename", INDIRECT("A1")),FIND("]",CELL("filename",INDIRECT("A1")))+1,255) & T(NOW())
Which resulted in the 'final' formula of,
=(INDEX("'"&PrevSheet_2&"'!P:P",MATCH(Information_A","'"&PrevSheet_2&"'!A:A",0)))
which doesn't work. This formula gives me a #VALUE! error.
I tested the formula without using PrevSheet_2 and typed in the worksheet name, e.g. April 30, and got the correct value, so I know that part is working. I also test PrevSheet_2 in a cell and got the correct previous sheet as well, so I know the problem lies in the combination of the 2.
My question, then, is how to make this
=(INDEX("'"&PrevSheet_2&"'!P:P",MATCH(Information_A","'"&PrevSheet_2&"'!A:A",0)))
formula work.
I have a feeling PrevSheet_2 is in the wrong data type however I don't know how to fix it.
EDIT:
I have also tried using INDIRECT (below) and got a #REF! error.
=INDEX(INDIRECT("''"&PrevSheet_2 &"'!P:P"),MATCH("Information_A",INDIRECT("'"&PrevSheet_2&"'!A:A"),0))
Refer this link .. Define SheetNames array (in Formulas > Define Name) as SheetNames = MID(GET.WORKBOOK(1),FIND("]",GET.WORKBOOK(1),1)+1,LEN(GET.WORKBOOK(1))) .. Then in excel formula you can get to previous sheet name as INDEX(SheetNames,SHEET()-1)
You can also define PreviousSheetName = INDEX(MID(GET.WORKBOOK(1),FIND("]",GET.WORKBOOK(1),1)+1,LEN(GET.WORKBOOK(1))),SHEET()-1)
You can put that in INDIRECT function as suggested by #BigBen
So Formula will be =INDEX(INDIRECT("'"&PreviousSheetName &"'!P:P"),MATCH("Information_A",INDIRECT("'"&PreviousSheetName&"'!A:A"),0))
See .. Sheet function gives us Index of the current sheet. So Sheet()-1 gives us Index of the previous sheet
After my answer I noted you have put single quotes TWICE in your indirect formula. Hence, the #REF error
Example:
=VLOOKUP(B2,'[Approved Contractors 08302018.xlsx]Contractor with key'!$B$2:$C$99999,2,0)
The file name for the spreadsheet named "Approved Contractors 08302018.xlsx" will change next week to "Approved Contractors 09062018.xlsx". The tab name in the spreadsheet is called "Contractor with key".
Currently, I have to go into the formula, update the date after the file name, then paste it into excel, then copy it down to all the cells. How to get I get it to update automatically. I was thinking =today()-8 but I'm not sure how to do it inside a vlookup for a file name?
Assuming that:
1. You only change the date in the filename (ex. only the 08302018 part)
2. This date is always formatted as mmddyyyy
3. This date is always =TODAY()-8
4. All other details remain the same (e.g worksheet name, source file being in the same folder as destination file, return values under column C, etc...)
Then you can use the INDIRECT function to automatically change that date within the formula:
=VLOOKUP(B2,INDIRECT("'[Approved Contractors "&TEXT(TODAY()-8,"mmddyyyy")&".xlsx]Contractor with key'!$B$2:$C$99999"),2,0)
However, I noticed that your example goes against the 3rd assumption, and that instead of referencing it to TODAY()-8, you want to reference it to the THURSDAY date of that current week. In that case, you just need to change the reference date in the above formula. Kindly consider the formula below:
=VLOOKUP(B2,INDIRECT("'[Approved Contractors "&TEXT(TODAY()-WEEKDAY(TODAY())+5,"mmddyyyy")&".xlsx]Contractor with key'!$B$2:$C$99999"),2,0)
To clarify, what this does is it changes the date in reference filename within the formula to the THURSDAY date of the current week. So when you run it in your file today (9/15/2018), the reference filename should be "Approved Contractors 09132018.xlsx".
If this returns an error, it may mean the supposed reference file was incorrectly named. In this case using an IFERROR function would alert us to check the reference filename. When an error does happen, the following formula would display "Please check reference filename":
=IFERROR(VLOOKUP(B2,INDIRECT("'[Approved Contractors "&TEXT(TODAY()-WEEKDAY(TODAY())+5,"mmddyyyy")&".xlsx]Contractor with key'!$B$2:$C$99999"),2,0),"Please check reference filename")
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.
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.