Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

COUNT function

The COUNT function counts the number of cells that contain numbers, and counts numbers within the list of
arguments. Use the COUNT function to get the number of entries in a number field that is in a range or array
of numbers. For example, you can enter the following formula to count the numbers in the range A1:A20:
=COUNT(A1:A20). In this example, if five of the cells in the range contain numbers, the result is 5.

Syntax

COUNT(value1, [value2], ...)

The COUNT function syntax has the following arguments:

▪ value1 Required. The first item, cell reference, or range within which you want to count numbers.
▪ value2, ... Optional. Up to 255 additional items, cell references, or ranges within which you want to
count numbers.

Note: The arguments can contain or refer to a variety of different types of data, but only numbers are
counted.

Remarks

▪ Arguments that are numbers, dates, or a text representation of numbers (for example, a number
enclosed in quotation marks, such as "1") are counted.
▪ Logical values and text representations of numbers that you type directly into the list of arguments are
counted.
▪ Arguments that are error values or text that cannot be translated into numbers are not counted.
▪ If an argument is an array or reference, only numbers in that array or reference are counted. Empty
cells, logical values, text, or error values in the array or reference are not counted.
▪ If you want to count logical values, text, or error values, use the COUNTA function.
▪ If you want to count only numbers that meet certain criteria, use the COUNTIF function or the
COUNTIFS function.

Example

Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to
show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to
see all the data.

Data

12/8/08

19

22.24
Data

TRUE

#DIV/0!

Formula Description Result

=COUNT(A2:A7) Counts the number of cells that contain numbers in cells A2 through A7. 3

=COUNT(A5:A7) Counts the number of cells that contain numbers in cells A5 through A7. 2

=COUNT(A2:A7,2) Counts the number of cells that contain numbers in cells A2 through A7, and
the value 2
COUNTIF function

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

Argument name Description

range (required) The group of cells you want to count. Range can contain numbers, arrays, a named
range, or references that contain numbers. Blank and text values are ignored.

Learn how to select ranges in a worksheet.

criteria (required) A number, expression, cell reference, or text string that determines which cells will
be counted.

For example, you can use a number like 32, a comparison like ">32", a cell like B4, or
a word like "apples".

COUNTIF uses only a single criteria. Use COUNTIFS if you want to use multiple
criteria.

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
Data Data

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 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 cells with a value greater than (>) or
COUNTIF(B2:B5,"<=85") equal to (=) 32 and less than (<) or equal to (=) 85 in cells B2
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 returned for long The COUNTIF function returns incorrect results when you use it to
strings. match 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 returned when you Be sure to enclose the criteria argument in quotes.
expect a value.

A COUNTIF formula receives a This error occurs when the formula that contains the function refers to
#VALUE! error when referring cells or a range in a closed workbook and the cells are calculated. For
to another worksheet. this feature to work, the other workbook must be open.

Best practices

Do this Why

Be aware that COUNTIF Criteria aren't case sensitive. In other words, the string "apples" and the string
ignores upper and "APPLES" will match the same cells.
lower case in text
strings.

Use wildcard Wildcard characters —the question mark (?) and asterisk (*)—can be used in
characters. 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 data When counting text values, make sure the data doesn't contain leading spaces,
doesn't contain trailing spaces, inconsistent use of straight and curly quotation marks, or
erroneous characters. nonprinting characters. In these cases, COUNTIF might return an unexpected
value.

Try using the CLEAN function or the TRIM function.

For convenience, use COUNTIF supports named ranges in a formula (such as =COUNTIF(fruit,">=32")-
named ranges COUNTIF(fruit,">85"). The named range can be in the current worksheet,
Do this Why

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