Sum with Sheet names as a variable instead of manually provided text

The_Wraith

New Member
Joined
Oct 20, 2017
Messages
6
Since I've been hacking away at this syntax for over an hour... I figured it was time to give up and ask people smarter than me. I want to take the following standard SUM syntax:

=SUM('Sheet3'!C5:C100)

And, instead of manually specifying "Sheet3" in the formula I want to include a variable of that sheet name. I have the Sheet names in a separate column. Assume the following:

B3 = Sheet3
B4 = Sheet4
B5 = Sheet5
B6 = Sheet6

What is the proper syntax for something like:

=SUM([B3]!C5:C100)
=SUM([B4]!C5:C100)
=SUM([B5]!C5:C100)
=SUM([B6]!C5:C100)

?

I've tried such things as INDIRECT and numerous attempts to get the values in "B#" into the SUM formula without success. Please advise. Thanks in advance.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try:
=SUM(INDIRECT(B3&"!C5:C100"))
 
Last edited:
Upvote 0
JoeMo said:
Try:
=SUM(INDIRECT(B3&"!C5:C100"))

This errored out with:
'Invalid Cell Reference error'


Marcelo Branco said:
Try:
=SUM(INDIRECT("'"&B3&"'!C5:C100"))

This appears to have worked perfectly. Thanks! It's kind of hard to discern that syntax - is that a (double quote) (single quote) (double quote) &B3 (double quote) (single quote) !C5:C100 (double quote) ?
 
Upvote 0
In terms of THIS manual Sheet formula:
=LOOKUP(2,1/('Sheet3'!C5:'Sheet3'!C999<>""),'Sheet3'!B$5:'Sheet3'!B$999)

How would I modify IT in the same manner you did with SUM?
 
Upvote 0
This appears to have worked perfectly. Thanks! It's kind of hard to discern that syntax - is that a (double quote) (single quote) (double quote) &B3 (double quote) (single quote) !C5:C100 (double quote) ?

"'" --> an apostrophe (red) between the quotes - to handle sheet names that contain space(s)
& --> to concatenate
B3 --> cell that contains the sheet name
& --> to concatenate
"'!C5:C100" --> apostrophe; exclamation mark ! ; range

M.
 
Upvote 0
"'" --> an apostrophe (red) between the quotes - to handle sheet names that contain space(s)
& --> to concatenate
B3 --> cell that contains the sheet name
& --> to concatenate
"'!C5:C100" --> apostrophe; exclamation mark ! ; range

M.

So, what am I mistaking here?

ORIGINAL:
=LOOKUP(2,1/('Sheet3'!C5:'Sheet3'!C999<>""),'Sheet3'!B$5:'Sheet3'!B$999)

MODIFIED:
=LOOKUP(2,1/(INDIRECT("'"&B3&"'")!C5:'Sheet3'!C999<>""),'Sheet3'!B$5:'Sheet3'!B$999)

NOTE: I only played with the syntax on the first "Sheet3". As, I assume the syntax would be the same for all other instances. Wouldn't that INDIRECT with with the quotes, concatenation, and quotes generate "Sheet3"?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top