Question

I need to count the number of rows for which one fixed cell matches the cells in another column and for which the corresponding cells in a third column are not blank. My formula, however, is behaving strangely, and I am not sure how to troubleshoot it...

Here is the raw data in the cells:

enter image description here

All of the cells in columns A through D contain only values. In cell E2 is the formula:

=SUMPRODUCT((--((A$1:A$6)=B2))*(IF(ISBLANK(C$1:C$6),0,1)))

The value that I was expecting, however, for cell E2, is 2. That would have been the number of cells in column A that match the value in cell B2 and for which the corresponding cell in column C is not blank. Unfortunately, it's producing 3 instead of 2 for cell E2, and I can't figure out why. In order to help me troubleshoot the issue, I entered the following array formula for cells G1 through G6:

{=--((A$1:A$6)=B2)}

And also the following array formula for cells H1 through H6:

{=IF(ISBLANK(C$1:C$6),0,1)}

Finally, I entered the following regular formula for cell I2:

=SUMPRODUCT((G1:G6)*(H1:H6))

This does yield the desired result of 2. However, I can't figure out what the difference is between the two approaches. My actual spreadsheet looks like columns A, B, and C, so the formula in E2, if it can produce the desired result, is preferable.

Thanks!

Was it helpful?

Solution

Try entering the formula as an array formula (Ctrl+Shift+Enter), that should work.

OTHER TIPS

As @Pash101 correctly noted, you should press CTRL+SHIFT+ENTER to evaluate your formula, or better use any of the following formulas instead (without array entry):

for Excel 2007 and later:

=COUNTIFS(A$1:A$6,B2,C$1:C$6,"<>")

for Excel 2003:

=SUMPRODUCT((A$1:A$6=B2)*(C$1:C$6<>""))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top