Excel COUNTIF function: how to count cells that meet a condition

The COUNTIF function counts the cells in a range that meet one condition. It takes two arguments: =COUNTIF(range,criteria). For example, =COUNTIF(B2:B11,"London") counts the cells in B2:B11 that contain exactly "London".
On the table below, that formula returns 4. Every example in this guide uses the same data, so you can copy it into a sheet and check each result yourself. If formulas are new to you, COUNTIF comes at step 4 of our beginner's plan for learning Excel, right after cell references.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Rep | City | Product | Amount (£) | Date |
| 2 | Emma | Leeds | Wireless keyboard | 120 | 03/01/2026 |
| 3 | James | London | 27-inch monitor | 450 | 07/01/2026 |
| 4 | Emma | London | Mouse | 80 | 12/01/2026 |
| 5 | Olivia | Bristol | Wired keyboard | 300 | 15/01/2026 |
| 6 | James | Leeds | HDMI cable | 95 | 22/01/2026 |
| 7 | Emma | Leeds | 24-inch monitor | 610 | 02/02/2026 |
| 8 | Harry | London | Wireless mouse | 250 | 05/02/2026 |
| 9 | Olivia | London | 27-inch monitor | 450 | 11/02/2026 |
| 10 | James | Bristol | USB-C cable | 40 | 18/02/2026 |
| 11 | Emma | Manchester | Wireless keyboard | 175 | 24/02/2026 |
COUNTIF syntax
=COUNTIF(range,criteria)
- range: the cells to check, for example
B2:B11. - criteria: the condition a cell must meet to be counted. It can be text (
"London"), a number (450), a comparison (">300"), a cell reference (G2) or a wildcard pattern ("Wireless*").
Three rules cover most cases:
- text and operators always go inside double quotes;
- COUNTIF is not case-sensitive:
"london"and"LONDON"also return 4; - COUNTIF takes a single condition. To combine several, use COUNTIFS (see below).
Count cells with specific text
The criteria must match the whole cell. =COUNTIF(C2:C11,"keyboard") returns 0, because no cell contains just "keyboard": they contain "Wireless keyboard" or "Wired keyboard". To count a word inside longer text, use the wildcards covered further down.
Use a cell as the criteria
Instead of typing the city into the formula, put it in a cell and refer to it. If G2 contains "Leeds":
=COUNTIF(B2:B11,G2)
The result is 3 (rows 2, 6 and 7). Change G2 and the count updates without editing the formula.
Count everything except one value
The <> operator means "not equal to". =COUNTIF(B2:B11,"<>London") returns 6: 10 sales minus the 4 in London.
Count numbers: equal to, greater than, less than
An exact number needs no quotes. For a comparison, put the operator and the number together inside quotes.
| Formula | What it counts | Result |
|---|---|---|
=COUNTIF(D2:D11,450) | amounts equal to 450 | 2 |
=COUNTIF(D2:D11,">300") | amounts greater than 300 | 3 |
=COUNTIF(D2:D11,">=300") | amounts greater than or equal to 300 | 4 |
=COUNTIF(D2:D11,"<100") | amounts less than 100 | 3 |
=COUNTIF(D2:D11,"<>450") | amounts other than 450 | 8 |
Threshold stored in a cell
When the threshold sits in a cell, keep the operator in quotes and join it to the reference with &. With 200 in G3:
=COUNTIF(D2:D11,">"&G3)
Result: 5 (450, 300, 610, 250 and 450). The usual mistake is ">G3": Excel then looks for the text "G3" and returns 0.
Count dates
Excel stores dates as numbers, so comparisons work the same way as with amounts. The safest approach is to build the date with the DATE function, which does not depend on regional date formats:
=COUNTIF(E2:E11,">="&DATE(2026,2,1))
This counts sales on or after 1 February 2026: 5 (rows 7 to 11). =COUNTIF(E2:E11,"<"&DATE(2026,1,15)) counts those before 15 January: 3.
To compare with today's date, use TODAY: =COUNTIF(E2:E11,"<"&TODAY()) counts past dates and updates every day.
Wildcards: *, ? and ~
In a text criteria, three characters have a special meaning:
*stands for any run of characters, including none;?stands for exactly one character;~placed before*or?makes Excel look for the literal character.
| Formula | What it counts | Result |
|---|---|---|
=COUNTIF(C2:C11,"Wireless*") | products starting with "Wireless" | 3 |
=COUNTIF(C2:C11,"*keyboard") | products ending with "keyboard" | 3 |
=COUNTIF(C2:C11,"*27*") | products containing "27" | 2 |
=COUNTIF(C2:C11,"2?-inch monitor") | "2" + one character + "-inch monitor" | 3 |
=COUNTIF(C2:C11,"*") | every cell that contains text | 10 |
"Contains" with a word typed in a cell
This is the most common request: count cells that contain a word entered somewhere else. Wrap the reference in asterisks, again with &. If G4 contains "wireless":
=COUNTIF(C2:C11,"*"&G4&"*")
Result: 3 (Wireless keyboard twice, Wireless mouse once).
Look for a real asterisk or question mark
If your cells hold codes such as "LOT*2", the criteria "LOT*2" would also count "LOT-A2" or "LOT12". Type "LOT~*2" to count only the literal asterisk. The same goes for ~?.
Count blank or non-blank cells
=COUNTIF(B2:B11,"")counts empty cells: 0 here.=COUNTIF(B2:B11,"<>")counts non-empty cells: 10 here.
COUNTBLANK and COUNTA do the same job without a criteria and read more clearly.
Two everyday uses
Flag duplicate values
Enter this in F2 and fill it down to F11:
=COUNTIF($A$2:$A$11,A2)
Each row shows how many times that rep appears: 4 for Emma, 3 for James, 2 for Olivia, 1 for Harry. The dollar signs lock the range as you fill down. =COUNTIF($A$2:$A$11,A2)>1 returns TRUE for any value that appears more than once, which also works as a conditional formatting rule. To then delete them, see how to remove duplicates in Excel.
Work out a percentage
=COUNTIF(B2:B11,"London")/COUNTA(B2:B11)
The result is 0.4. Apply the Percentage format to read 40% of sales made in London.
More than one condition: add up or switch to COUNTIFS
To count sales in London or Leeds (two values in the same column), add two COUNTIFs together:
=COUNTIF(B2:B11,"London")+COUNTIF(B2:B11,"Leeds")
Result: 7 (4 + 3).
When conditions must all be true at once, such as Emma's sales in Leeds, COUNTIF is not enough. You need COUNTIFS: =COUNTIFS(A2:A11,"Emma",B2:B11,"Leeds") returns 2. Full syntax, date ranges and OR logic across columns are in COUNTIFS with multiple criteria.
To add up amounts rather than count rows, the matching function is SUMIF. To fetch a piece of information rather than count it (a product's price, a customer's city), VLOOKUP returns the matching value.
When COUNTIF returns an unexpected result
- 0 although the value is visible: a stray space before or after the text ("London ") is enough to break the match. TRIM cleans those cells.
- Operator in the wrong place: write
">"&G3, not">G3"or>"G3". - #VALUE!: the range points to another workbook that is closed. Open that workbook and the formula calculates.
- Text longer than 255 characters: COUNTIF cannot match strings that long and returns a wrong result or #VALUE!.
The same causes affect COUNTIFS. They are covered, with fixes, in COUNTIFS not working: causes and fixes. Microsoft's reference page is on Microsoft Support.


