0% found this document useful (0 votes)
85 views7 pages

COUNTIF Function: Examples

The COUNTIF function counts the number of cells that meet criteria specified in a formula. It has the basic syntax of =COUNTIF(range, criteria) and counts cells in a range that match the criteria. Examples show how COUNTIF can count cells that contain specific text, numbers greater than or less than values, and match patterns using wildcard characters. Best practices include being aware that COUNTIF is not case sensitive for text, using wildcard characters to match partial strings, and ensuring data does not contain erroneous characters.

Uploaded by

Rahul Madhavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views7 pages

COUNTIF Function: Examples

The COUNTIF function counts the number of cells that meet criteria specified in a formula. It has the basic syntax of =COUNTIF(range, criteria) and counts cells in a range that match the criteria. Examples show how COUNTIF can count cells that contain specific text, numbers greater than or less than values, and match patterns using wildcard characters. Best practices include being aware that COUNTIF is not case sensitive for text, using wildcard characters to match partial strings, and ensuring data does not contain erroneous characters.

Uploaded by

Rahul Madhavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

COUNTIF function

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel


for the web More...

Use COUNTIF, one of the statistical functions, to


count the number of cells that meet a criterion; for
example, to count the number of times a particular
city appears in a customer list.

In its simplest form, COUNTIF says:

 =COUNTIF(Where do you want to look?, What do


you want to look for?)

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 Counts the number
:A5,A3) 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
Data Data
per expression. You
could also use
the COUNTIFS functi
on.
=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
COUNTIF(B2:B5,">85") of cells with a value
greater than (>) or
equal to (=) 32 and
Data Data
less than (<) or equal
to (=) 85 in cells B2
through B5. The
result is 3.
=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.

To match strings longer than 255


characters, use the CONCATENATE
function or the concatenate operator
&. For example, =COUNTIF(A2:A5,"long
string"&"another long string").
No value Be sure to enclose
returned when the criteria argument in quotes.
you expect a
value.
A COUNTIF This error occurs when the formula that
formula receives contains the function refers to cells or a
a #VALUE! error range in a closed workbook and the
when referring to cells are calculated. For this feature to
another work, the other workbook must be
worksheet. open.

Best practices
Do this Why
Be aware that Criteria aren't case sensitive. In other
COUNTIF ignores words, the string "apples" and the
upper and lower string "APPLES" will match the same
case in text cells.
strings.
Use wildcard Wildcard characters —the question
characters. mark (?) and asterisk (*)—can be used
in criteria. A question mark matches
any single character. An asterisk
matches any sequence of characters. If
you want to find an actual question
mark or asterisk, type a tilde (~) in front
of the character.

For example,
=COUNTIF(A2:A5,"apple?") will count all
instances of "apple" with a last letter
that could vary.
Make sure your When counting text values, make sure
data doesn't the data doesn't contain leading
contain spaces, trailing spaces, inconsistent use
erroneous of straight and curly quotation marks,
characters. or nonprinting characters. In these
cases, COUNTIF might return an
unexpected value.
Do this Why

Try using the CLEAN function or


the TRIM function.
For convenience, COUNTIF supports named ranges in a
use named formula (such as
ranges =COUNTIF(fruit,">=32")-
COUNTIF(fruit,">85"). The named
range can be in the current worksheet,
another worksheet in the same
workbook, or from a different
workbook. To reference from another
workbook, that second workbook also
must be open.
Note: The COUNTIF function will not count cells based on cell background or font color.
However, Excel supports User-Defined Functions (UDFs) using the Microsoft Visual Basic for
Applications (VBA) operations on cells based on background or font color. Here is an example of
how you can Count the number of cells with specific cell color by using VBA.

You might also like