Conditional totals function
COUNTIF function in Google Sheets and Excel
COUNTIF counts the cells in a range that meet one condition.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
COUNTIF(range, criteria)Arguments in [brackets] are optional. Google Sheets writes it COUNTIF(range, criterion).
Example
=COUNTIF(B2:B9,"North") reads: Count the cells in the region column B2:B9 that say North.
| A | B | C | D | E | F | G | H | I | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Rep | Region | Jul | Aug | Sep | Target | North reps | 2 | |
| 2 | Amara Osei | North | $12,400 | $13,100 | $11,800 | $36,000 | |||
| 3 | Ben Fischer | South | $9,800 | $10,250 | $12,100 | $30,000 | |||
| 4 | Lina Chen | East | $15,200 | $14,800 | $16,900 | $45,000 | |||
| 5 | Diego Alvarez | West | $8,700 | $9,100 | $8,400 | $28,000 | |||
| 6 | Eva Novak | North | $11,200 | $12,600 | $13,900 | $36,000 | |||
| 7 | Farid Haddad | South | $13,300 | $12,900 | $14,100 | $39,000 | |||
| 8 | Grace Kim | East | $10,100 | $9,600 | $10,800 | $33,000 | |||
| 9 | Hugo Martin | West | $14,500 | $15,800 | $15,100 | $42,000 |
I1 shows 2: Amara and Eva are the two North reps.
How the spreadsheet calculates it
Counts the cells in B2:B9 whose value is equal to "North".
- 1. COUNTIF: Counts the cells in
B2:B9whose value is equal to"North".range=`B2:B9`: the cells to checkcriteria=`"North"`: what to count
More COUNTIF examples
=COUNTIF(B2:B9,"North")How many reps are in the North.=COUNTIF(F2:F13,">="&K1)How many orders have at least the quantity in K1.=COUNTIF($A$2:$A$11,A2)>1TRUE for a value that appears more than once.=COUNTIF(A2:A20,"<>")How many cells aren't empty.
Paste any of these into the formula explainer to see it step by step.
Tips
- Use
$on the range when filling down, or each row counts a shifted range. - Join comparisons with
&(">="&K1) instead of typing the cell inside quotes. - For several conditions, switch to COUNTIFS rather than nesting or adding COUNTIFs.
- For “contains”, put wildcards around the text:
"*pot*"counts every cell with pot anywhere in it.
What COUNTIF is used for
Counting orders per status, attendees per city or tickets per agent, finding duplicates (a count above 1), and checking that an entry exists in a list.
Arguments
| Argument | Required | What it is |
|---|---|---|
| range | Yes | The cells to check. |
| criteria | Yes | The condition: a number, text in quotes, a comparison in quotes like ">32", a cell like B4, or a wildcard pattern.Watch out: A cell inside the quotes (">K1") is read as text. |
Common mistakes
Unquoted comparisons:
COUNTIF(F2:F13,>2)won't calculate.Expecting it to match case: “north” and “NORTH” count the same.
Matching text longer than 255 characters, which Microsoft says gives wrong results.
In Google Sheets
Google Sheets' COUNTIF reads criteria the same way, with the same * and ? wildcards and ~ to match them literally.
Errors you may see with COUNTIF
- #VALUE!: The range is in another workbook that's closed.
Questions
How do I count with more than one condition?
Use COUNTIFS. See COUNTIF vs COUNTIFS.
How do I count cells that contain a word?
Wildcards on both sides: COUNTIF(A2:A20, "*pot*"), or from a cell, "*"&K1&"*". See COUNTIF with a cell reference.
How do I count blank cells?
COUNTIF(range, "") counts empty cells; COUNTBLANK does the same job.
Can COUNTIF count by color?
No: COUNTIF tests values, not formatting. Count by the rule behind the color instead (the same condition you used for conditional formatting).
Does COUNTIF count numbers stored as text?
A criteria like ">10" compares numbers, so a value imported as text doesn't pass it. Convert the column with VALUE first; lookup numbers stored as text shows how to tell which cells are text.
What's the difference between COUNT, COUNTA and COUNTIF?
COUNT counts cells holding numbers, COUNTA counts every non-empty cell, and COUNTIF counts the cells that meet a condition you choose. See SUM, AVERAGE and COUNT.
Sources
Official documentation the facts on this page were checked against.