简体   繁体   中英

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. Rather than say 'Sheet 1' it needs to be something similar to =A5

I have read about using INDIRECT, however am unable to get this to work

=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

eg

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

sheet1 : has cell A5 = 55

sheet2 : has cell A5 = 125

sheet2 : has cell D2 = sheet1

sheet2 : has cell F3 = INDIRECT("'" & D2 & "'!A5")

sheet2 : has now cell F3 = 55


now duplicate sheet2

copy of sheet2 : change value of D2 = sheet2

copy of sheet2 : has now cell F3 = 125


I spent one hour to understand this. Hope this helps anyone.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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