Google Sheets recipe
How to count cells that are not blank in Google Sheets
=COUNTA(A2:A6) is the shortest way to count non-blank cells, and =COUNTIF(A2:A6, "<>") gives the same count on the sample data. Both count a cell whose formula returns "" or that holds only a space, so use LEN when those must not count.
Steps
- Select the range to count and note its address, for example A2:A6.
- Enter =COUNTA(A2:A6) for a fast count of filled cells.
- Or use =COUNTIF(A2:A6, "<>"), which behaves the same on this data.
- If formulas returning "" should count as blank, use =SUMPRODUCT(--(LEN(A2:A6)>0)).
- If cells with only a space should count as blank too, wrap the range in TRIM inside LEN.
- To count text cells with at least one character, ignoring numbers, try =COUNTIF(A2:A6, "?*"). A cell with a space counts as text.
Examples
The examples use this table, starting in A1:
| Note |
| a |
| ="" |
| 7 |
=COUNTA(A2:A6)Result: 4
Counts every cell that is not truly empty: a, the empty-string formula, the space and 7. Result 4.
Run in a Google Sheet (English US locale) on .
=COUNTIF(A2:A6, "<>")Result: 4
Same answer as COUNTA here: the empty-string formula still counts as filled.
Run in a Google Sheet (English US locale) on .
=SUMPRODUCT(--(LEN(A2:A6)>0))Result: 3
Counts cells with at least one character. The empty-string formula drops out, the space stays. Result 3.
Run in a Google Sheet (English US locale) on .
=SUMPRODUCT(--(LEN(TRIM(A2:A6))>0))Result: 2
TRIM also removes the space, so only a and 7 remain. Result 2.
Run in a Google Sheet (English US locale) on .
=COUNTIF(A2:A6, "?*")Result: 2
Text with at least one character. The number 7 is not counted, but the space is.
Run in a Google Sheet (English US locale) on .
Common errors
- A formula that returns "" looks empty but COUNTA counts it. In the sample, A2:A4 holds a value, an empty cell and an empty-string formula, and COUNTA returns 2.
- A single space is content. COUNTA on a cell holding only a space returns 1, and TRIM inside LEN is needed to ignore it.
- COUNTIF with "" as criterion counts both the truly empty cell and the empty-string formula, so it is not a count of non-blank cells.
Compared with Excel
COUNTA, COUNTIF, SUMPRODUCT, LEN and TRIM exist in Excel with the same syntax. The counts with empty text from formulas were measured in Google Sheets only.