简体   繁体   English

通过单元格变量引用另一张表?

[英]Reference another sheet by cell variable?

What I am trying to do is to create a formula which references another sheet. 我正在尝试创建一个引用另一张纸的公式。 Rather than adding the name of the sheet directly, I want to be able to have the sheet name as a variable. 我希望能够直接将工作表名称作为变量,而不是直接添加工作表的名称。

My formula is as follows: 我的公式如下:

=IF(B2="",(HLOOKUP($A$2,'Sheet 1'!$C$5:$AB$200,2)),(HLOOKUP($B$2,'Sheet 1'!$C$5:$AB$200,2)))

Sheet 1 is the sheet that is being referenced statically here, however cell A5 will be the cell which determines which sheet to look at. 工作表1是此处静态引用的工作表,但是单元格A5将是确定要查看哪个工作表的单元格。 Rather than say 'Sheet 1' it needs to be something similar to =A5 与其说“ Sheet 1”,不如说它类似于= A5

I have read about using INDIRECT, however am unable to get this to work 我已经读过有关使用INDIRECT的信息,但是无法使它正常工作

=IF(B2="",(HLOOKUP($A$2,(INDIRECT(CONCATENATE("'",A5,"'"))!$C$5:$AB$200,2)),(HLOOKUP($B$2,(INDIRECT(CONCATENATE("'",A5,"'"))!$C$5:$AB$200,2)))

If anyone can assist, that would be much appreciated 如果有人可以提供帮助,将不胜感激

To use Indirect , you need to build the whole address as a string 要使用Indirect ,您需要将整个地址构建为字符串

eg 例如

INDIRECT("'" & A5 & "'!$C$5:$AB$200")

sheet1 : has cell A5 = 55 sheet1:具有单元格A5 = 55

sheet2 : has cell A5 = 125 sheet2:具有单元格A5 = 125

sheet2 : has cell D2 = sheet1 sheet2:具有单元格D2 = sheet1

sheet2 : has cell F3 = INDIRECT("'" & D2 & "'!A5") sheet2:具有单元格F3 = INDIRECT(“'”&D2&“'!A5”)

sheet2 : has now cell F3 = 55 sheet2:现在具有单元格F3 = 55


now duplicate sheet2 现在重复sheet2

copy of sheet2 : change value of D2 = sheet2 工作表2的副本:D2的更改值=工作表2

copy of sheet2 : has now cell F3 = 125 sheet2的副本:现在具有单元格F3 = 125


I spent one hour to understand this. 我花了一个小时来了解这一点。 Hope this helps anyone. 希望这对任何人有帮助。

Thank you. 谢谢。

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

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