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

By Emma Updated 2 November 2026 5 min read

COUNTIF: Count cells that match

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.

ABCDE
1RepCityProductAmount (£)Date
2EmmaLeedsWireless keyboard12003/01/2026
3JamesLondon27-inch monitor45007/01/2026
4EmmaLondonMouse8012/01/2026
5OliviaBristolWired keyboard30015/01/2026
6JamesLeedsHDMI cable9522/01/2026
7EmmaLeeds24-inch monitor61002/02/2026
8HarryLondonWireless mouse25005/02/2026
9OliviaLondon27-inch monitor45011/02/2026
10JamesBristolUSB-C cable4018/02/2026
11EmmaManchesterWireless keyboard17524/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.

FormulaWhat it countsResult
=COUNTIF(D2:D11,450)amounts equal to 4502
=COUNTIF(D2:D11,">300")amounts greater than 3003
=COUNTIF(D2:D11,">=300")amounts greater than or equal to 3004
=COUNTIF(D2:D11,"<100")amounts less than 1003
=COUNTIF(D2:D11,"<>450")amounts other than 4508

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.
FormulaWhat it countsResult
=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 text10

"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.

Emma · Writer, Excel Zone

Emma writes the tutorials on formulas and data cleaning: COUNTIF, SUMIF, DATEDIF, duplicates, drop-down lists. Each method is shown on a small table you can copy.