Count each row as 1 if there is a value in any column

Viewed 211

I have a table with data in a range from B2:F74 and I want to count once for each row if any column of that row is not blank. I found an easy way to do this for one row:

 =IFERROR(COUNTIF(B2:F2, "<>" & "")/COUNTIF(B2:F2, "<>" & ""),"")

and I know I can copy that down a column and add it together (which is what I'm currently using) but I was curious if there was an easy way to do this using a formula in only one cell.

A long way to do this would be:

 =IFERROR(COUNTIF(B2:F2, "<>" & "")/COUNTIF(B2:F2, "<>" & ""),"") + IFERROR(COUNTIF(B3:F3, "<>" & "")/COUNTIF(B3:F3, "<>" & ""),"") + ...

and adding it up individually. I tried

 =SUM(IFERROR(COUNTIF(B2:F2, "<>" & "")/COUNTIF(B2:F2, "<>" & ""),""),IFERROR(COUNTIF(B74:F74, "<>" & "")/COUNTIF(B74:F74, "<>" & ""),""))

but that returns "1".

edit: fixed typo in title.

2 Answers

Use OFFSET to create a range of one row and iterate the rows, using SUMPRODUCT to tally the results:

=SUMPRODUCT(--(COUNTIF(OFFSET(B1,ROW($1:$73),0,1,5),"<>")>0))

enter image description here

I prefer the non-volatile array formula**:

=SUM(N(MMULT(N(B2:F74<>""),TRANSPOSE(COLUMN(B2:F74)^0))>0))

Regards

**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

Related