简体   繁体   English

在Excel公式中使用串联字符串获取单元格值

[英]Use concatenated string in Excel formula to get the cell value

I have a sheet named Vessel Reading 1. I want to read the value of the cell D4 into another sheet. 我有一个名为Vessel Reading 1的工作表。我想将单元格D4的值读入另一工作表中。 'Vessel Reading 1'!D4 gives me the value properly. 'Vessel Reading 1'!D4给我正确的值。

But, I want to be able to get the latest number instead of just 'Vessel Reading 1'. 但是,我希望能够获得最新的数字,而不仅仅是“船只读数1”。 Eg if I have five sheets named 'Vessel Reading 1 to 5', I want to read the value from sheet named 'Vessel Reading 5'. 例如,如果我有五个名为“ Vessel Reading 1 to 5”的表格,我想从名为“ Vessel Reading 5”的表格中读取值。 Basically, 'Vessel Reading 1'!D4 should be changed to 'Vessel Reading N'!D4 where N is the latest sheet. 基本上, 'Vessel Reading 1'!D4应该更改为'Vessel Reading N'!D4 ,其中N是最新的表格。

CONCATENATE("Vessel Reading ",RIGHT(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))),1))

Above sheet gives me the sheet name that I want. 表格上方为我提供了所需的表格名称。 Eg if I am in sheet 5, it gives me 'Vessel Reading 5', and if I am in sheet 2, it gives me 'Vessel Reading 2'. 例如,如果我在工作表5中,则为我提供“船只读数5”,如果我在工作表2中,则为我提供“船只读数2”。

So, clearly, most of the work is already in place. 因此,显然,大部分工作已经就绪。 Sadly, when I use 可悲的是,当我使用

'CONCATENATE("Vessel Reading ",RIGHT(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))),1))'!D4

it throws an error. 它抛出一个错误。 Now I am not sure what am I missing in this formula. 现在,我不确定该公式中缺少什么。

Edit: 编辑:

Basically, I need a way to put the result of concatenate as a string to create cell reference. 基本上,我需要一种将串联的结果作为字符串创建单元格引用的方法。

If you place your formula for the sheet name in A1 then you can use this formula to find out value of D4 cell from that sheet. 如果将工作表名称的公式放在A1中,则可以使用此公式从该工作表中查找D4单元格的值。

=INDIRECT(CONCATENATE("'",A1,"'!D4"))

You can replace the A1 in the formula above with the code you created to find out the sheet and all will be in single formula. 您可以将上面公式中的A1替换为您创建的代码以查找工作表,所有代码都将在一个公式中。 Full formula would look like 完整的公式看起来像

=INDIRECT(CONCATENATE("'",CONCATENATE("Vessel Reading ",RIGHT(RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1))),1)),"'!D4"))

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

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