## How to use the COUNTIF function

*Article updated on March 29, 2018*

The COUNTIF function calculates the number of cells that is equal to a condition.

Formula in cell D3:

Lucy is found twice, in cell B3 and B7, the function returns 2 in cell D3.

### Excel Function Syntax

COUNTIF(*range*, *criteria*)

### Arguments

range |
Required. The cell range you want to count the cells meeting a condition. |

criteria |
Required. The condition that you want to count. |

### Comments

The condition is not case sensitive.

### Table of Contents

- Example 1 - Count with single criterion
- Example 2 - Count cells larger/less than a criterion
- Example 3 - Count cells containing a text string
- Example 4 - Absolute and relative cell reference
- Example 5 - Array formula
- Download example file

### Example 1 - Count with a single criterion

The following formula in cell D5 counts the number of cells within cell range C6:C13 that meet criterion "Lucy":

=COUNTIF(C6:C13, "Lucy")

### Example 2 - Count cells larger/less than a criterion

The following formula in cell D5 counts the number of cells within cell range C6:C13 that is larger than or equal to 500:

### Example 3 - Count cells containing a text string

The following formula in cell D5 counts the number of cells within cell range C6:C13 that contains the text string "apple":

### Example 4 - Absolute and relative cell reference

Formula in cell C6:

=COUNTIF($B$6:B6,B6)

$B$6:B6 is a cell reference to cell B6. When the cell is copied to cells below, the cell reference changes. The first part $B$6 i always locked to cell B6, the last part B6 changes. Cell range $B$6:B6 "grows" when you copy the cell.

This technique is used in this popular post: Filter unique distinct values

In cell C20:

=COUNTIF($B$6:B20,B20)

becomes

=COUNTIF({"Watermelon"; "Banana"; "Orange"; "Kiwi"; "Lemon"; "Apple"; "Apricot"; "Banana"; "Pear"; "Apple"; "Pineapple"; "Banana"; "Pear"; "Pear"; "**plum**"},"**plum**") and returns 1 in cell C20.

### Example 5 - Array formula

Array formula in cell range C6:C20:

=COUNTIF(B6:B20, B6:B20)

**How to enter an array formula**

- Select cell range C6:C20
- Copy / Paste formula to formula bar

- Press and hold CTRL + SHIFT
- Press Enter
- Release all keys

**Explaining the array formula**

The COUNTIF function counts the number of cells within a range that meet a single criterion. In this example I am using multiple values in the criteria argument.

Each value is in the criteria argument is used as a criterion and the returning array has the same number of values as the criteria argument.

The technique described here is used in this popular post: Count unique distinct values

=COUNTIF(B6:B20, B6:B20)

becomes

=COUNTIF({"Watermelon"; "Banana"; "Orange"; "Kiwi"; "Lemon"; "Apple"; "Apricot"; "Banana"; "Pear"; "Apple"; "Pineapple"; "Banana"; "Pear"; "Pear"; "plum"},{"Watermelon"; "Banana"; "Orange"; "Kiwi"; "Lemon"; "Apple"; "Apricot"; "Banana"; "Pear"; "Apple"; "Pineapple"; "Banana"; "Pear"; "Pear"; "plum"})

and returns {1; 3; 1; 1; 1; 2; 1; 3; 3; 2; 1; 3; 3; 3; 1} in cell range C6:C20.

### Download excel *.xlsx file

### Articles with the 'COUNTIF' Function

The following 16 articles have formulas that contain the COUNTIF function.

Extract unique distinct values from a multi-column cell range

Question: I have cell values spanning over several columns and I want to create a unique list from that range. […]### Functions in 'Statistical'

The COUNTIF function function is one of many functions in the 'Statistical' category.

### 5 Responses to “How to use the COUNTIF function”

### Leave a Reply

**How to add a formula to your comment:**

<code>your formula</code>

Remember to convert less than and larger than signs to html character entities before you post your comment.

**How to add VBA code to your comment:**

[vb 1="vbnet" language=","]

VBA code

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org

Add picture link to comment.

**Contact Oscar**

You can contact me through this webpage

[...] COUNTIF(range,criteria) Counts the number of cells within a range that meet the given condition [...]

[…] COUNTIF(range,criteria) Counts the number of cells within a range that meet the given condition […]

[…] COUNTIF(range,criteria) Counts the number of cells within a range that meet the given condition […]

[…] COUNTIF(range,criteria) Counts the number of cells within a range that meet the given condition […]

I need a formula that will count the number of cells containing dates in column C1 to C10 that are less than or equal to the dates in column A1 to A10.