﻿ COUNTIF function

# COUNTIF function

This article describes the formula syntax and usage of the COUNTIFfunction in Microsoft Excel.

## Description

The COUNTIF function counts the number of cells within a range that meet a single criterion that you specify. For example, you can count all the cells that start with a certain letter, or you can count all the cells that contain a number that is larger or smaller than a number you specify. For example, suppose you have a worksheet that contains a list of tasks in column A, and the first name of the person assigned to each task in column B. You can use the COUNTIF function to count how many times a person's name appears in column B and, in that way, determine how many tasks are assigned to that person. For example:

=COUNTIF(B2:B25,"Nancy")

Note   To count cells based on multiple criteria, see COUNTIFS function.

## Syntax

COUNTIF(range, criteria)

The COUNTIF function syntax has the following arguments:

• range    Required. One or more cells to count, including numbers or names, arrays, or references that contain numbers. Blank and text values are ignored.

• criteria    Required. A number, expression, cell reference, or text string that defines which cells will be counted. For example, criteria can be expressed as 32, ">32", B4, "apples", or "32".

Note

• You can use the wildcard characters — the question mark (?) and the asterisk (*) — in criteria. A question mark matches any single character, and an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.

• Criteria are case insensitive; for example, the string "apples" and the string "APPLES" will match the same cells.

## Remarks

• The COUNTIF function returns incorrect results when you use it to match strings longer than 255 characters to the string #VALUE!.

## Examples

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 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 (using criterion in A4) in cells A2 through A5. The result is 1. =COUNTIF(A2:A5,A3)+COUNTIF(A2:A5,A2) Counts the number with oranges (using criterion in A3) and apples (using criterion in A2) in cells A2 through A5. The result is 3. =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 "<>" (not equal to) and the value in B4 to read =COUNTIF(B2:B5,"<>75"). The result is 3. =COUNTIF(B2:B5,">=32")-COUNTIF(B2:B5,">85") Counts the number of cells with a value greater than or equal to 32 and 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 wildcard character * is used to match any character. The result is 4. =COUNTIF(A2:A5,"?????es") Counts the number of cells that have exactly 7 characters that end with the letters es in cells A2 through A5. The wildcard character ? is used to match individual characters. The result is 2.

Applies To: Excel 2007, Excel 2010, Excel Starter, Excel Online, SharePoint Online

﻿