Ben A
Ben A

Reputation: 219

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

Upvotes: 1

Views: 1386

Answers (1)

Grade 'Eh' Bacon
Grade 'Eh' Bacon

Reputation: 3843

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.

Upvotes: 1

Related Questions