COUNTIF function - Microsoft Support (2024)

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 function - Microsoft Support (1)

COUNTIF(range, criteria)

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

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")-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 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 strings.

The COUNTIF function returns incorrect results when you use it to 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 expect a value.

Be sure to enclose the criteria argument in quotes.

A COUNTIF formula receives a #VALUE! error when referring to another worksheet.

This error occurs when the formula that contains the function refers to cells or a range in a closed workbook and the cells are calculated. For this feature to work, the other workbook must be open.

Best practices

Do this

Why

Be aware that COUNTIF ignores upper and lower case in text strings.

Criteria aren't case sensitive. In other words, the string "apples" and the string "APPLES" will match the same cells.

Use wildcard characters.

Wildcard characters —the question 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 data doesn't contain erroneous characters.

When counting text values, make sure the data doesn't contain leading spaces, trailing spaces, inconsistent use of straight and curly quotation marks, or nonprinting characters. In these cases, COUNTIF might return an unexpected value.

Try using the CLEAN function or the TRIM function.

For convenience, use named ranges

COUNTIF supports named ranges in a formula (such as =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.

Need more help?

You can always ask an expert in the Excel Tech Communityor get support inCommunities.

See also

COUNTIFS function

IF function

COUNTA function

Overview of formulas in Excel

IFS function

SUMIF function

COUNTIF function - Microsoft Support (2024)

FAQs

What are the limitations of Countif function in Excel? ›

There are two main limitations to the COUNTIFS Function on Excel. Range Size: The range sizes for each criteria range must always be the same. For example, having criteria_range1 with 5 rows and criteria_range2 with 10 will return a #VALUE! error.

What is the problem with Countif function in Excel? ›

Reasons Why Countif Doesn't Work in Excel. External Workbook References: Closed workbooks referenced in formulas can hinder COUNTIF's functionality. Concatenation of Cell References: Neglecting to concatenate cell references with operators can lead to errors.

How do I count the number of answers in Excel? ›

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).

How do I count specific responses in Excel? ›

Count how often a single value occurs by using the COUNTIF function. Use the COUNTIF function to count how many times a particular value appears in a range of cells.

Why is the Countif function not counting correctly? ›

Try removing the space between the quotes. You are counting all cells with 1 space in the cell. Blanks are counted with the quotes together. When counting blanks though, its also good to use a COUNTIFS and compare the blank off another column that always has a value.

Is there a limit to countifs? ›

The COUNTIFS function limits text strings to 255 characters, so it's important to ensure the text gives a concise description of the data in as few characters as possible.

What is the alternative to Countif function in Excel? ›

SUMPRODUCT. Another way to count cells with OR logic in Excel is to use the SUMPRODUCT function in this way: SUMPRODUCT(1*(range ={criterion1, criterion2, criterion3, …}))

What is the difference between Countif and Countifs? ›

The difference is that COUNTIF is designed for counting cells with a single condition in one range, whereas COUNTIFS can evaluate different criteria in the same or in different ranges.

What are the advantages of Countif function in Excel? ›

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.

How do I count different answers in Excel? ›

Count the number of unique values by using a filter
  1. Select the range of cells, or make sure the active cell is in a table. ...
  2. On the Data tab, in the Sort & Filter group, click Advanced. ...
  3. Click Copy to another location.
  4. In the Copy to box, enter a cell reference. ...
  5. Select the Unique records only check box, and click OK.

How do I calculate answers in Excel? ›

For simple formulas, simply type the equal sign followed by the numeric values that you want to calculate and the math operators that you want to use — the plus sign (+) to add, the minus sign (-) to subtract, the asterisk (*) to multiply, and the forward slash (/) to divide.

How do I total answers in Excel? ›

Use the SUBTOTAL function to count the number of values in an Excel table or range of cells. If the table or range contains hidden cells, you can use SUBTOTAL to include or exclude those hidden cells, and this is the biggest difference between SUM and SUBTOTAL functions.

How do I use countif with two conditions? ›

How to Countif Multiple Criteria? The Excel formula to countif multiple criteria[1] is =countifs(). The “s” on the end makes it plural and, therefore, implies that there are multiple criteria (2 or more).

How to use countif formula in Excel with example? ›

For example, the formula =COUNTIF(D2:D9,"*>5*") will count all cells in the range D2:D9 with contents like this "Delivery >5 days" or ">5 available".

How do you count occurrences in Excel? ›

If you're in Excel 365, the function =UNIQUE() will output unique rows from a range (works on a multi-column range), and you can then use =COUNTIFS next to that to get the number of occurences.

What is the range of Countifs? ›

COUNTIFS syntax

criteria_range1 (required) - defines the first range to which the first condition (criteria1) shall be applied. criteria1 (required) - sets the condition in the form of a number, cell reference, text string, expression or another Excel function.

How many conditions can Countifs have? ›

Up to 127 range/criteria pairs are allowed.

Which of the following is not true about the COUNTIF function? ›

Which of the following is not true about the COUNTIF function? It contains as many arguments as you have conditions.

Does Countif only work with numbers? ›

COUNTIF can be used to count cells that contain dates, numbers, and text. Criteria can include logical operators (>,<,<>,=) and wildcards (*,?).

Top Articles
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6025

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.