简体   繁体   中英

How to reference cell within '' worksheet title

I have the names of the tabs/worksheets (M-61,M-62,M-63W) at the top row (A1, B1, C1...etc) I am trying to get a sum of several cells within the different sheets:

=SUM('M-60'!H21,'M-60'!H43,'M-60'!H86,'M-60'!H87,'M-60'!H97,'M-60'!H98)

However, right now I'm referring to the sheet itself, and have to apply the same formula to all the other sheets. This will require me to manually go and change all the sheet titles accordingly. I was wondering if there is any way to reference the top row with the sheet titles within the formula so it automatically refers to the row text instead of me having to manually change the sheet title.

Edit Now i got the reference to work, just wondering how would I do a sum of several cells in that tab

=INDIRECT("'"&$F1&"'!H87",TRUE)

Maybe:

=SUM(INDIRECT("'"&C1&"'!H21"),INDIRECT("'"&C1&"'!H43"),INDIRECT("'"&C1&"'!H86:H87"),INDIRECT("'"&C1&"'!H97:H98"))  

(though there may well be a much smarter way).

You can use the INDIRECT function, which uses a string as an argument and converts it to a range. So

=M-60'!H21

is the same as

=INDIRECT("M-60'!H21")

or, if Sheet name is stored in, say, cell C1:

=INDIRECT(C1&"'!H21")

Your example has a SUM, though, which requires some adaptations. This your example:

=SUM('M-60'!H21,'M-60'!H43,'M-60'!H86,'M-60'!H87,'M-60'!H97,'M-60'!H98)

Since you are not using a range, you can convert that SUM into simple addition. Assuming Sheet name in cell C1

=INDIRECT("'"&C1&"'!H21")+INDIRECT("'"&C1&"'!H43")+INDIRECT("'"&C1&"'!H86")+INDIRECT("'"&C1&"'!H87")+INDIRECT("'"&C1&"'!H97")+INDIRECT("'"&C1&"'!H98")

This should solve your problem. More info here

By the way, if you were using a range, the OFFSET function with INDIRECT as an argument would work. But that's not necessary here.

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