SUMPRODUCT & INDIRECT Cell to Sheet Name

shemayisroel

Well-known Member
Joined
Sep 11, 2008
Messages
1,867
Hi,

Attempting to use SUMPRODUCT with INDIRECT to link a cell reference to a sheet name.

Basic structure is below but throws back a #REF! error. Any suggestions on how to clean it up and yield the desired result?

=SUMPRODUCT(--(INDIRECT(cellref&"!Range1")=Criteria1),--(INDIRECT(cellref&"!Range2")=Criteria2),INDIRECT(cellref&"!SumRange"))

Thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi,

Attempting to use SUMPRODUCT with INDIRECT to link a cell reference to a sheet name.

Basic structure is below but throws back a #REF! error. Any suggestions on how to clean it up and yield the desired result?

=SUMPRODUCT(--(INDIRECT(cellref&"!Range1")=Criteria1),--(INDIRECT(cellref&"!Range2")=Criteria2),INDIRECT(cellref&"!SumRange"))

Thanks
You want something like...

=SUMPRODUCT(
--(INDIRECT("'"&A2&"'!E2:E10")=Criteria1),
--(INDIRECT("'"&A2&"'!F2:F10")=Criteria2),
INDIRECT("'"&A2&"'!G2:G10"))

where G2:G10 stands for the sum range.
 
Upvote 0
Hi,

Attempting to use SUMPRODUCT with INDIRECT to link a cell reference to a sheet name.

Basic structure is below but throws back a #REF! error. Any suggestions on how to clean it up and yield the desired result?

=SUMPRODUCT(--(INDIRECT(cellref&"!Range1")=Criteria1),--(INDIRECT(cellref&"!Range2")=Criteria2),INDIRECT(cellref&"!SumRange"))

Thanks
If your sheet name contains space characters or numbers then you have to put single quotes around the sheet name:

...INDIRECT("'"&cellref&"'!Range")...

Here it is in "exploded" view:

...INDIRECT(" ' " & cellref & " ' ! Range")...

Also, if the ranges are dynamic ranges defined using functions like OFFSET then INDIRECT won't work.
 
Last edited:
Upvote 0
Aladin Akyurek & T Valko - thanks very much for a quick response.

I'll give it a go within the WB and report back if I encounter any issues.
 
Upvote 0
Just tried it in the WB and retruned #REF! error.

Here it is

=SUMPRODUCT(--(INDIRECT(""&P$3&"'!$A$1:$A$:500")=$C7),--(INDIRECT(""&P$3&"'!$L$1:$L$500")=P$4),INDIRECT(""&P$3&"'!$F$1:$F$500"))

P3 = sheetname = contains a number than work like "3sample"

3sample sheet does exist and is in lower case

Any ideas...
 
Upvote 0
Just tried it in the WB and retruned #REF! error.

Here it is

=SUMPRODUCT(--(INDIRECT(""&P$3&"'!$A$1:$A$:500")=$C7),--(INDIRECT(""&P$3&"'!$L$1:$L$500")=P$4),INDIRECT(""&P$3&"'!$F$1:$F$500"))

P3 = sheetname = contains a number than work like "3sample"

3sample sheet does exist and is in lower case

Any ideas...
You have the quotes wrong at the beginning.

Try it like this...

=SUMPRODUCT(--(INDIRECT("'"&P$3&"'!A1:A500")=$C7),--(INDIRECT("'"&P$3&"'!L1:L500")=P$4),INDIRECT("'"&P$3&"'!F1:F500"))

Also, notice that I removed the $ signs from some of the ranges.

Since these ranges are being defined within the INDIRECT function they are TEXT strings and as such they will never change if the formula is copied to other locations and they will automatically be evaluated as absolute references.
 
Upvote 0
You have the quotes wrong at the beginning.

Try it like this...

=SUMPRODUCT(--(INDIRECT("'"&P$3&"'!A1:A500")=$C7),--(INDIRECT("'"&P$3&"'!L1:L500")=P$4),INDIRECT("'"&P$3&"'!F1:F500"))

Also, notice that I removed the $ signs from some of the ranges.

Since these ranges are being defined within the INDIRECT function they are TEXT strings and as such they will never change if the formula is copied to other locations and they will automatically be evaluated as absolute references.
Sometimes all those stupid quotes are hard to see/read. Here's the syntax verbatim:

double quote single quote double quote & P$3 & double quote single quote exclamation mark

" ' " & P$3 & " ' !
 
Upvote 0
Sometimes all those stupid quotes are hard to see/read. Here's the syntax verbatim:

double quote single quote double quote & P$3 & double quote single quote exclamation mark

" ' " & P$3 & " ' !
Agree - and thank you for taking the time to

a) Resolve it for me - it now works :)

b) Explaining it a little further

I usually avoid using INDIRECT in this way, however this is what the client wanted :-)
 
Upvote 0
Just tried it in the WB and retruned #REF! error.

Here it is

=SUMPRODUCT(--(INDIRECT(""&P$3&"'!$A$1:$A$:500")=$C7),--(INDIRECT(""&P$3&"'!$L$1:$L$500")=P$4),INDIRECT(""&P$3&"'!$F$1:$F$500"))

P3 = sheetname = contains a number than work like "3sample"

3sample sheet does exist and is in lower case

Any ideas...

Should be like:

=SUMPRODUCT(
--(INDIRECT("'"&P$3&"'!A1:A500")=$C7),
--(INDIRECT("'"&P$3&"'!L1:L500")=P$4),
INDIRECT("'"&P$3&"'!F1:F500"))
 
Upvote 0
Agree - and thank you for taking the time to

a) Resolve it for me - it now works :)

b) Explaining it a little further

I usually avoid using INDIRECT in this way, however this is what the client wanted :-)
You're welcome. Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,856
Members
452,948
Latest member
UsmanAli786

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