• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

Excel SumProduct using CountA

What is the correct way to use CountA for a dynamic row in a SumProduct?

This works fine;


but this gives me a #VALUE error;

=SUMPRODUCT(("Pnl!$I$2:$IJ$" & COUNTA(Data!$G:$G))*(Data!$I$1:$IJ$1=Sumary!D$1)*("Pnl!$G$2:$G$" & COUNTA(Data!$G:$G)=Sumary!$A6)*("Pnl!$A$2:$A$" & COUNTA(Data!$G:$G)="D"))

even though my CountA=66
1 Solution
I think you would need to use the Offset function:

Which would be easier if you set dynamic named ranges first, then used those in the formula.
barry houdiniCommented:
Try putting the COUNTA formula in a cell, e.g. Z2  and then use this version


If you don't want a reference cell just put COUNTA(Data!$G:$G) in place of the three $Z$2s

regards, barry
I agree with The_Barman.  I frequently used dynamic named ranges for such tasks.  See the following link explaining how do define these dynamic ranges from the Microsoft website.

This greatly simplifies formulas.


newparadigmzAuthor Commented:
@ barry, this didn't work for me. does it work for you?

"If you don't want a reference cell just put COUNTA(Data!$G:$G) in place of the three $Z$2s"
barry houdiniCommented:
Yes, works for me, see attached

The formula in D7 copied across and down is the same as suggested above, then the versions in D14:F16 are the same. Highlighted cells E7 and E14 pick up the highlighted values from the Data sheet, so D14 is this version


You may also want to check out the dynamic ranges suggested by others here - you can use effectively the same formula but define

Headers as =Data!$I$1:$IJ$1
Range1 as =Data!$G$2:INDEX(Data!$G:$G,COUNTA(Data!$G:$G))
Range2 as =Data!$A$2:INDEX(Data!$A:$A,COUNTA(Data!$G:$G))


Range3 as =Data!$I$2:INDEX(Data!$IJ:$IJ,COUNTA(Data!$G:$G))

then you get just


regards, barry
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now