The COUNTIF function
COUNTIF answers "how many?" questions: how many orders came from Leeds, how many scores were over 50, how many times a name appears.
The condition can be an exact value, a comparison in quotes such as ">=5", or a pattern using * (any characters) and ? (one character). Text matches ignore upper and lower case.
=COUNTIF(range, criteria)
Arguments
- range
- The cells to test.
- criteria
- The condition: a value like "Leeds", a cell like E1, a comparison like ">=5", or a wildcard like "Y*".
Try it
=COUNTIF(B2:B7,"Leeds") in E2. Three rows in the branch column say Leeds, so COUNTIF gives 3.
E2
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Volunteer | Branch | Hours | Leeds volunteers | ||
| 2 | Amy Watson | Leeds | 6 | 3 | ||
| 3 | Ben Carter | York | 3 | |||
| 4 | Chloe Patel | Leeds | 8 | |||
| 5 | Dan Robson | Hull | 4 | |||
| 6 | Eve Clarke | York | 12 | |||
| 7 | Femi Adeyemi | Leeds | 5 | |||
| 8 | ||||||
| 9 |
Edit the formula in E2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =COUNTIF(C2:C7,">=5") | 4 | Shifts of 5 hours or more. The operator and number go inside the quotes together. |
| =COUNTIF(B2:B7,"<>Leeds") | 3 | Everyone not at Leeds. |
| =COUNTIF(A2:A7,"*son") | 2 | A wildcard: names ending in son (Watson and Robson). |
| =COUNTIF(B2:B7,B3) | 2 | The condition can be a cell. B3 says York, which appears twice. |
Tips
- To compare with a number in a cell, join the operator on:
">"&F1. - Find duplicates by counting each value in its own column:
=COUNTIF($A$2:$A$7,A2)>1is TRUE for any repeated name. - For two or more conditions, such as Leeds and over 5 hours, use COUNTIFS.
Common mistakes
- The result is 0 though matches are visible.Check for extra spaces in the data ("Leeds " isn't "Leeds"). TRIM the column, or use a wildcard like
"Leeds*". - A formula like `=COUNTIF(C2:C7,>=5)` won't go in.The comparison must be in quotes:
">=5". - `">F1"` counts nothing.Inside quotes, F1 is just text. Write
">"&F1so the cell's value is used.
Practise COUNTIF with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.