Sub topic 7
Counting Filled and Empty Cells with COUNTA and COUNTBLANK
What this chapter assumes
You should already know how to select a range such as B2:B6, and that a formula starts with =. You should also know how COUNT works. COUNT counts only numeric cells, so it skips text, logical values, errors, and blanks. This chapter covers the two functions that answer different questions about the same range: how many cells hold anything, and how many hold nothing.
Three counters, three questions
| Function | Question it answers | Counts |
|---|---|---|
| `COUNT` | How many cells hold numbers? | Numbers, dates, times |
| `COUNTA` | How many cells are not empty? | Numbers, text, logical values, errors, and formulas that return `""` |
| `COUNTBLANK` | How many cells look empty? | Truly empty cells and formulas that return `""` |
The "A" in COUNTA stands for "all". It counts everything that has been entered, whatever its type.
COUNTA: counting everything that is filled
COUNTA takes one or more arguments, each a cell, a range, or a value. Like SUM, it accepts several arguments in one call.
=COUNTA(B2:B6)
=COUNTA(B2:B6, D2:D6)A cell counts when it contains any content at all:
- a number or a date
- text, including text that looks like a number
TRUEorFALSE- an error value such as
#N/Aor#DIV/0! - a formula that returns an empty string (
"") - a single space, which you cannot see
Only a truly empty cell is skipped. Formatting does not matter. A cell that is colored, bordered, or formatted as a number but holds nothing is still empty.
The most common use is counting records. If column A holds one customer name per row, the number of customers is:
=COUNTA(A2:A100)Start the range below the header row. If you write A1:A100, the header cell is counted too and the answer is one too high.
COUNTBLANK: counting what is missing
COUNTBLANK takes exactly one range. It does not accept a list of arguments, so =COUNTBLANK(B2:B6, D2:D6) is an error. Add two separate calls instead:
=COUNTBLANK(B2:B6)
=COUNTBLANK(B2:B6) + COUNTBLANK(D2:D6)COUNTBLANK counts two kinds of cells:
- Cells that are truly empty.
- Cells that contain a formula returning
""(an empty string).
It does not count a cell holding 0, even if a number format hides the zero. It also does not count a cell holding a space.
A worked example
Suppose B2:B6 holds survey scores. The entries are mixed on purpose:
| Cell | Content | What it is |
|---|---|---|
| B2 | 120 | Number |
| B3 | N/A | Text |
| B4 | (nothing) | Truly empty |
| B5 | 85 | Number |
| B6 | `=""` | Formula returning an empty string |
Now apply the three counters.
=COUNT(B2:B6)
=COUNTA(B2:B6)
=COUNTBLANK(B2:B6)The results are 2, 4, and 2.
COUNTreturns 2, for B2 and B5.COUNTAreturns 4. It counts B2, B3, B5, and B6.COUNTBLANKreturns 2. It counts B4 and B6.
B6 is counted by both COUNTA and COUNTBLANK. That is the main surprise in this chapter, and the next section explains it.
The empty-string trap
A formula cell is never truly empty. A formula such as =IF(A6="", "", A6*2) returns a value, and when the condition is met that value is a string with zero characters. Excel treats it two ways:
- As content, because the cell holds a formula. So
COUNTAcounts it. - As visually blank, because the displayed text is empty. So
COUNTBLANKcounts it.
This breaks a tempting identity. For a range with no empty-string formulas, the two functions always add up to the number of cells:
=COUNTA(B2:B6) + COUNTBLANK(B2:B6)
=ROWS(B2:B6) * COLUMNS(B2:B6)Both formulas return 5 when no cell is a formula returning "". In the example above, the first returns 6 while the range has only 5 cells, because B6 is counted twice. If your totals exceed the cell count, look for formulas that return "".
Finding cells that only look empty
When a count is off, test the suspicious cell directly. Suppose B4 looks empty:
=ISBLANK(B4)
=LEN(B4)ISBLANK returns TRUE only for a truly empty cell. LEN returns the number of characters, so a cell holding one space returns 1. A formula returning "" gives FALSE from ISBLANK but 0 from LEN.
If the extra content is spaces from a data import, clear the cells with the Delete key rather than typing over them. Cells filled by formulas need the formula itself changed.
Choosing the right function
The diagram sums up the decision. Start from what you want to know about the range.
Useful patterns
Completion rate
To find the share of cells that have been filled in, divide the filled count by the total number of cells:
=COUNTA(B2:B6) / ROWS(B2:B6)Format the result as a percentage. This overstates completion if any cells hold "" formulas, so use it on ranges with typed entries only.
Non-numeric entries
Every filled cell is either a number or something else. Subtract the numeric count from the filled count to see how many "something else" cells there are:
=COUNTA(B2:B6) - COUNT(B2:B6)In the worked example this returns 2, for the text in B3 and the empty string in B6. A nonzero result is a quick check for numbers stored as text, which SUM and AVERAGE silently skip.
Guarding an average
Chapter-level errors such as #DIV/0! come from averaging a range with no numbers. A guard that tests for numbers, not just filled cells, is the right one:
=IF(COUNT(B2:B6)=0, "No data", AVERAGE(B2:B6))COUNTA would be the wrong test here. A range holding only text has a COUNTA above zero, yet AVERAGE still fails.
Counting across a table
To count filled cells in a rectangular block, give COUNTA the whole block:
=COUNTA(A2:D100)COUNTBLANK works on blocks in the same way. This is handy for finding how many answers are missing from a form where each row is a person and each column is a question.
Edge cases and gotchas
- Whole-column references.
=COUNTA(A:A)counts the header and anything else in the column, such as notes or totals.=COUNTBLANK(A:A)returns a number above one million, because it counts every empty row down to the bottom of the sheet. Use a bounded range for blanks. - Hidden and filtered rows. Both functions count cells in hidden rows. To count filled cells while ignoring hidden or filtered rows, use
=SUBTOTAL(103, B2:B6). Function number 103 isCOUNTAwith hidden rows excluded. A later chapter coversSUBTOTAL. - Errors count as filled. A cell showing
#N/Ais counted byCOUNTA.COUNTAitself never returns an error because of its inputs, butCOUNTandCOUNTAtogether can hide an error in the data. Compare them when a total looks wrong. - Logical values.
TRUEandFALSEin a range are counted byCOUNTAbut not byCOUNT. - Zero is not blank. A cell containing
0is a number.COUNTandCOUNTAcount it, andCOUNTBLANKdoes not. - Direct arguments. For
COUNTA, a value typed straight into the formula is counted, including"". For example,=COUNTA("", 5)returns 2.
Summary
COUNTA counts every cell that has content, and COUNTBLANK counts cells that look empty. A formula returning "" is counted by both, so the two do not always add up to the cell count. Use COUNT when only numbers matter, COUNTA for records and responses, and COUNTBLANK for gaps. When a result seems wrong, test the doubtful cell with ISBLANK and LEN.
Exercise
Range C2:C7 holds these entries: C2 = 40, C3 = the text "pending", C4 = an empty cell, C5 = TRUE, C6 = a formula that returns "", C7 = 0. What do COUNT, COUNTA, and COUNTBLANK return for C2:C7? Then write a formula for the number of filled cells that are not numbers, and say what it returns.
Show answer
COUNT returns 2 (C2 and C7; text, TRUE, and "" are not numbers). COUNTA returns 5 (C2, C3, C5, C6, C7; only C4 is truly empty). COUNTBLANK returns 2 (C4 and C6; C7 holds 0, which is a number, not a blank). The non-numeric formula is =COUNTA(C2:C7)-COUNT(C2:C7), which returns 3 (the text in C3, TRUE in C5, and the empty string in C6).