Google Code

Monday, 5 December 2016

Count cells that are not blank

Generic formula 
=COUNTA(rng)
To count the number of cells are not blank, use the COUNTA function. In the generic form of the formula (above) rng represents a range of cells.
In the example, the active cell contains this formula:
=COUNTA(B4:B8)

How this formula works

COUNTA is fully automatic. When given a range of cells, it counts cells that contain numbers, text, logical values, and errors. COUNTA does not count empty cells. 
To count cells that are blank, you can use the COUNTBLANK function like so:
=COUNTBLANK(B4:B8)

Count cells with at least one character

One problem with COUNTA is that it will also count null strings returned by formulas (""). If you run into this problem, you can try a formula like this:
=SUMPRODUCT(--(LEN(A1:A100)>0))
The LEN function returns a character count, so SUMPRODUCT will count only cells that contain least 1 character.

No comments:

Post a Comment