Excel COUNTIF Function
Excel COUNTIF Function
Summary
COUNTIF is a function to count cells that meet a single criterion. COUNTIF can be
used to count cells with dates, numbers, and text that meet specific criteria. The
COUNTIF function supports logical operators (>,<,<>,=) and wildcards (*,?) for
partial matching.
Purpose
Count cells that match criteria
Return value
A number representing cells counted.
Syntax
=COUNTIF (range, criteria)
Arguments
range - The range of cells to count.
criteria - The criteria that controls which cells should be counted.
Usage notes
The COUNTIF function in Excel counts the number of cells in a range that match one
supplied condition. Criteria can include logical operators (>,<,<>,=)
and wildcards (*,?) for partial matching. Criteria can also be based on a value from
another cell, as explained below.
Examples
In the example show, the following formulas are used:
=COUNTIF(D5:D12,">100") // count sales over 100
=COUNTIF(B5:B12,"jim") // count name = "jim"
=COUNTIF(C5:C12,"ca") // count state = "ca"
Notice COUNTIF is not case-sensitive.
Double quotes ("") in criteria
In general, text values need to be enclosed in double quotes, and numbers do not.
However, when a logical operator is included with a number, the number and operator
must be enclosed in quotes, as seen in the second example below:
=COUNTIF(A1:A10,100) // count cells equal to 100
=COUNTIF(A1:A10,">32") // count cells greater than 32
=COUNTIF(A1:A10,"jim") // count cells equal to "jim"
Value from another cell
A value from another cell can be included in criteria using concatenation. In the
example below, COUNTIF will return the count of values in A1:A10 that are less than
the value in cell B1. Notice the less than operator (which is text) is enclosed in quotes.
=COUNTIF(A1:A10,"<"&B1) // count cells less than B1
Wildcards
The wildcard characters ? and * can be used in criteria. A question mark matches any
one character and an asterisk matches any sequence of characters. To find a literal
question mark or asterisk, use a tilde (~) in front question mark or asterisk (i.e. ~?,
~*).
Notes
COUNTIF returns incorrect results when used to match strings longer than 255
characters.
COUNTIF will return a #VALUE error when referencing another workbook
that is closed.
Related videos
How to create a dynamic named range with a Table
In this video, we'll look at how to create a dynamic named range with a Table. This is
the simplest way to create a dynamic named range in Excel.
Related functions