COUNTIF Function
COUNTIF Function
Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for
the web More...
For example:
=COUNTIF(A2:A5,"London")
=COUNTIF(A2:A5,A4)
Syntax
Examples
To use these examples in Excel, copy the data in the
table below, and paste it in cell A1 of a new worksheet.
Data Data
apples 32
oranges 54
peaches 75
apples 86
Formula Description
=COUNTIF(A2:A5,"apples") Counts the number of
cells with apples in cells
A2 through A5. The result
is 2.
=COUNTIF(A2:A5,A4) Counts the number of
cells with peaches (the
value in A4) in cells A2
through A5. The result is
1.
=COUNTIF(A2:A5,A2)+COUNTIF(A2:A5,A3 Counts the number of
) apples (the value in A2),
and oranges (the value in
A3) in cells A2 through
A5. The result is 3. This
formula uses COUNTIF
twice to specify multiple
criteria, one criteria per
Data Data
expression. You could
also use
the COUNTIFS function.
=COUNTIF(B2:B5,">55") Counts the number of
cells with a value greater
than 55 in cells B2
through B5. The result is
2.
=COUNTIF(B2:B5,"<>"&B4) Counts the number of
cells with a value not
equal to 75 in cells B2
through B5. The
ampersand (&) merges
the comparison operator
for not equal to (<>) and
the value in B4 to read
=COUNTIF(B2:B5,"<>75").
The result is 3.
=COUNTIF(B2:B5,">=32")- Counts the number of
COUNTIF(B2:B5,"<=85") cells with a value greater
than (>) or equal to (=)
32 and less than (<) or
equal to (=) 85 in cells B2
Data Data
through B5. The result is
1.
=COUNTIF(A2:A5,"*") Counts the number of
cells containing any text
in cells A2 through A5.
The asterisk (*) is used as
the wildcard character to
match any character. The
result is 4.
=COUNTIF(A2:A5,"?????es") Counts the number of
cells that have exactly 7
characters, and end with
the letters "es" in cells A2
through A5. The question
mark (?) is used as the
wildcard character to
match individual
characters. The result is 2.
Common Problems
Problem What went wrong
Wrong value The COUNTIF function returns incorrect
returned for long results when you use it to match strings
strings. longer than 255 characters.
Best practices
Do this Why
Be aware that Criteria aren't case sensitive. In
COUNTIF ignores other words, the string "apples" and
upper and lower case the string "APPLES" will match the
in text strings. same cells.