Sub topic 3
Counting non-empty and empty cells with COUNTA and COUNTBLANK
This chapter assumes you can enter formulas in Google Sheets, read cell addresses such as B2, and write a range such as B2:B6.
Counting filled and empty cells
COUNTA counts every non-empty cell in a range, including text, numbers, and errors. COUNTBLANK counts the empty cells in a range. COUNT counts only the cells that hold numbers.
=COUNTA(A2:A6)
=COUNTBLANK(B2:B6)| Goal | Function |
|---|---|
| Count numeric cells | COUNT |
| Count all filled cells | COUNTA |
| Count empty cells | COUNTBLANK |
Using whole-column references
Write B:B to refer to all of column B. New rows fall inside the reference automatically, and text headers are ignored by SUM.
=SUM(B:B)Common errors and handling them with IFERROR
AVERAGE returns #DIV/0! when its range holds no numbers. IFERROR returns a replacement value when a formula produces an error.
=IFERROR(AVERAGE(B2:B6), "No data")IFERROR hides every error, including errors that signal a broken reference. Check the formula before you hide its errors.
Rounding results and nesting functions
ROUND takes a number and a count of decimal places. Nesting AVERAGE inside ROUND rounds the average itself.
=ROUND(AVERAGE(B2:B6), 2)Number formatting changes only the display. ROUND changes the stored value.
Next step: SUMIF, COUNTIF, and AVERAGEIF
These functions apply a condition before they calculate. AVERAGEIF takes a criteria range, a criterion, and an average range.
=SUMIF(A2:A6, "Apples", B2:B6)
=COUNTIF(B2:B6, ">100")Aggregating filtered data with SUBTOTAL
SUBTOTAL skips rows hidden by a filter. Its first argument selects the function: 9 for SUM, 1 for AVERAGE, 2 for COUNT, and 3 for COUNTA.
=SUBTOTAL(9, B2:B100)Exercise
Range B2:B6 holds 10, "n/a", an empty cell, 5, and 0. What do COUNT, COUNTA, and COUNTBLANK return for this range?
Show answer
COUNT returns 3 (10, 5, and 0). COUNTA returns 4 (10, "n/a", 5, and 0). COUNTBLANK returns 1.