简体   繁体   English

Excel单元格使用以前的日期作为名称对其他工作簿的引用

[英]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. 幸运的是,文件名的格式很好,为“ 2016 01 January.xlsm”,因此使用公式引用它们并不难。

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. 我可以在Matlab中轻松调试串联,但是可悲的是我不在那种环境中,而且我似乎不太了解Excel的工作方式。

Thanks in advance! 提前致谢! Ben

You simply need to prepend your formula with the INDIRECT command. 您只需要在公式前面加上INDIRECT命令即可。 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. INDIRECT告诉excel您不是显式地引用特定位置,而是要动态地计算位置,然后引用该计算出的位置。 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. 要测试它是否正确创建了文件名,请考虑将串联公式放在其他单元格中,然后使用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. *编辑为“吉普(Jeeped)”突出显示的内容,现在可以正确地计算文件名,而不是将其硬编码为文本的显式字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM