I'm struggling to make the following formula dynamic and be able to change the cells if references.
I have this formula which works fine:
=SUMPRODUCT(SUMIF(INDIRECT("'"&Sheets!$C$1:$AM$1&"'!A:A"),$A4,INDIRECT("'"&Sheets!$C$1:$AM$1&"'!"&C$1)))
However in sheet 'Sheets' I may not always want to look up $AM$1. So I have tried changing the formula to use Counta and Address to make the reference dynamic, however when I try the following I get #REF!
=SUMPRODUCT(SUMIF(INDIRECT("'"&"Sheets!$C$1:"&ADDRESS(1,COUNTA(Sheets!1:1))&"'!A:A"),$A4,INDIRECT("'"&Sheets!$C$1:$AM$1&"'!"&D$1)))
As a check I also tried typing Sheets!$C$1:$AM$1 in cell O4 and then the following formula which also gave a #REF! error:
=SUMPRODUCT(SUMIF(INDIRECT("'"&O4&"'!A:A"),$A4,INDIRECT("'"&Sheets!$C$1:$AM$1&"'!"&E$1)))
The fact that this last version doesn't work makes me think that it isn't possible, but would love to be proved wrong on this...
I have this formula which works fine:
=SUMPRODUCT(SUMIF(INDIRECT("'"&Sheets!$C$1:$AM$1&"'!A:A"),$A4,INDIRECT("'"&Sheets!$C$1:$AM$1&"'!"&C$1)))
However in sheet 'Sheets' I may not always want to look up $AM$1. So I have tried changing the formula to use Counta and Address to make the reference dynamic, however when I try the following I get #REF!
=SUMPRODUCT(SUMIF(INDIRECT("'"&"Sheets!$C$1:"&ADDRESS(1,COUNTA(Sheets!1:1))&"'!A:A"),$A4,INDIRECT("'"&Sheets!$C$1:$AM$1&"'!"&D$1)))
As a check I also tried typing Sheets!$C$1:$AM$1 in cell O4 and then the following formula which also gave a #REF! error:
=SUMPRODUCT(SUMIF(INDIRECT("'"&O4&"'!A:A"),$A4,INDIRECT("'"&Sheets!$C$1:$AM$1&"'!"&E$1)))
The fact that this last version doesn't work makes me think that it isn't possible, but would love to be proved wrong on this...