Excel count if there is a number of

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)

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

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 Community or get support in the Answers community.

Get live and free answers on Excel

See also

COUNTIFS function

IF function

COUNTA function

Overview of formulas in Excel

IFS function

SUMIF function

Need more help?

The COUNTIF function is included in the group of statistical functions. It allows you to find the number of cells by a certain criterion. The COUNTIF function works with numeric and text values, as well as with dates.



Syntax and features of the function

First, let’s consider the arguments:

COUNTIF.

  • Range – the group of values for analysis and counting (required).
  • Criteria – the condition by which cells are to be counted (required).

The range of cells can include textual and numerical values, dates, arrays, and references to numbers. The function ignores empty cells.

A criterion can be a reference, a number, a text string, or an expression. The COUNTIF function only works with one criterion (by default). However, you can “force” it to analyze two criteria simultaneously.

Recommendations for the correct operation of the function:

  1. If the COUNTIF function refers to a range in another workbook, this workbook must be opened.
  2. The «Criteria» argument must be enclosed in quotation marks (except for references).
  3. The function does not take into account the letter case.
  4. When formulating a counting condition, you can use wildcard characters. The question mark «?» is any character. The asterisk «*» is any sequence of characters. For the formula to search for these signs directly, put a tilde (~) before them.
  5. For normal operation of the formula, cells with text values should not contain spaces or non-printable characters.



Countif function in Excel: examples

Let’s count the numerical values in one range. The counting condition is one criterion.

We have the following table:

following table.

Count the number of cells with numbers greater than 100. Formula: =COUNTIF(B1:B11,»>100″). The range is В1:В11. The counting criterion is «>100». The result:

umbers greater.

If the counting condition is entered in a separate cell, you can use the reference as a criterion:

reference as a criterion.

Count the text values in one range. The search condition is one criterion. Formula: =COUNTIF(A1:A11,A3).

Formula.

Or used reference inside the table:

inside table.

In the second case, the cell reference was used as a criterion, result is the same – 2.

Formula with the wildcard character application: =COUNTIF(A1:A11,»Tab*»). To calculate the number of values ending in «и» and containing any number of characters: =COUNTIF(A1:A11,»*s»). We obtain:

result.

All names that end with a letter «s».

We use the search condition «not equal» in the COUNTIF.

Formula: =COUNTIF(A1:A11,»<>»&»Stools»). The operator «<>» means «not equal». The ampersand sign (&) is used to merge this operator and the “Stools” value.

Stools.

When you apply a reference, the formula will look like this:

apply a reference.

Often you need to perform the COUNTIF function in Excel by two criteria. In this way, you can significantly expand its capabilities. Let’s consider special cases of using the COUNTIF function in Excel and examples with two criteria.

  1. Let’s count how many cells are contained in the » Tables » and » Chairs » text. Formula:

    To specify several criteria, several COUNTIF phrases are used. They are united by the «+» operator.

  2. .

  3. Criteria – cell references. Formula:

    The function searches for » Tables » text in cell A1 and » Chairs » text – in cell A2 based on the criterion.

  4. based on the criterion.

  5. Count the number of cells in B1:B11 range with a value greater than or equal to 100 and less than or equal to 200. Formula:
  6. value greater.

  7. Apply several ranges in the COUNTIF function. This is possible if the ranges are contiguous. It searches for values by two criteria in two columns simultaneously. If the ranges are not adjacent, then the COUNTIFS function is used.
  8. simultaneously.

  9. When the criterion is a reference to a range of cells with conditions, the function returns the array. To enter a formula, you need to highlight as many cells as the range with criteria contains. After entering the arguments, simultaneously press Shift + Ctrl + Enter control key combination. Excel recognizes the formula of the array.

array.

COUNTIF with two criteria in Excel is very often used for automated and efficient data handling. Therefore, an advanced user is highly recommended to carefully study all of the examples above.

Subtotal command and the countif function

Count the number of goods sold in groups.

  1. First, sort the table so that the same values are close.
  2. Sort.

  3. The first argument of the formula “SUBTOTAL” – “Function number”. These are numbers from 1 to 11, indicating a statistical function for calculating the intermediate result. Counting the number of cells is carried out under number «2» (“COUNT”).

SUBTOTAL.

Download example COUNTIF in Excel

The formula has found the number of values for the «Chairs» group. For a large number of rows (more than a thousand), this combination of functions can be useful.

Excel has many functions where a user needs to specify a single or multiple criteria to get the result. For example, if you want to count cells based on multiple criteria, you can use the COUNTIF or COUNTIFS functions in Excel.

This tutorial covers various ways of using a single or multiple criteria in COUNTIF and COUNTIFS function in Excel.

While I will primarily be focussing on COUNTIF and COUNTIFS functions in this tutorial, all these examples can also be used in other Excel functions that take multiple criteria as inputs (such as SUMIF, SUMIFS, AVERAGEIF, and AVERAGEIFS).

An Introduction to Excel COUNTIF and COUNTIFS Functions

Let’s first get a grip on using COUNTIF and COUNTIFS functions in Excel.

Excel COUNTIF Function (takes Single Criteria)

Excel COUNTIF function is best suited for situations when you want to count cells based on a single criterion. If you want to count based on multiple criteria, use COUNTIFS function.

Syntax

=COUNTIF(range, criteria)

Input Arguments

  • range –  the range of cells which you want to count.
  • criteria – the criteria that must be evaluated against the range of cells for a cell to be counted.

Excel COUNTIFS Function (takes Multiple Criteria)

Excel COUNTIFS function is best suited for situations when you want to count cells based on multiple criteria.

Syntax

=COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)

Input Arguments

  • criteria_range1 – The range of cells for which you want to evaluate against criteria1.
  • criteria1 – the criteria which you want to evaluate for criteria_range1 to determine which cells to count.
  • [criteria_range2] – The range of cells for which you want to evaluate against criteria2.
  • [criteria2] – the criteria which you want to evaluate for criteria_range2 to determine which cells to count.

Now let’s have a look at some examples of using multiple criteria in COUNTIF functions in Excel.

Using NUMBER Criteria in Excel COUNTIF Functions

#1 Count Cells when Criteria is EQUAL to a Value

To get the count of cells where the criteria argument is equal to a specified value, you can either directly enter the criteria or use the cell reference that contains the criteria.

Below is an example where we count the cells that contain the number 9 (which means that the criteria argument is equal to 9). Here is the formula:

=COUNTIF($B$2:$B$11,D3)

Using multiple criteria in Excel Functions - number equal to

In the above example (in the pic), the criteria is in cell D3. You can also enter the criteria directly into the formula. For example, you can also use:

=COUNTIF($B$2:$B$11,9)

#2 Count Cells when Criteria is GREATER THAN a Value

To get the count of cells with a value greater than a specified value, we use the greater than operator (“>”). We could either use it directly in the formula or use a cell reference that has the criteria.

Whenever we use an operator in criteria in Excel, we need to put it within double quotes. For example, if the criteria is greater than 10, then we need to enter “>10” as the criteria (see pic below):

Here is the formula:

=COUNTIF($B$2:$B$11,”>10″)

Using Multiple Criteria in Excel COUNTIF Function - Greater Than

You can also have the criteria in a cell and use the cell reference as the criteria. In this case, you need NOT put the criteria in double quotes:

=COUNTIF($B$2:$B$11,D3)

Using Multiple Criteria in Excel COUNTIF Function - - Greater Than criteria in cell reference

There could also be a case when you want the criteria to be in a cell, but don’t want it with the operator. For example, you may want the cell D3 to have the number 10 and not >10.

In that case, you need to create a criteria argument which is a combination of operator and cell reference (see pic below):

=COUNTIF($B$2:$B$11,”>”&D3)

Using Multiple Criteria in Excel COUNTIF Function - Greater Than operator and cell referenceNOTE: When you combine an operator and a cell reference, the operator is always in double quotes. The operator and cell reference are joined by an ampersand (&).

#3 Count Cells when Criteria is LESS THAN a Value

To get the count of cells with a value less than a specified value, we use the less than operator (“<“). We could either use it directly in the formula or use a cell reference that has the criteria.

Whenever we use an operator in criteria in Excel, we need to put it within double quotes. For example, if the criterion is that the number should be less than 5, then we need to enter “<5” as the criteria (see pic below):

=COUNTIF($B$2:$B$11,”<5″)

Using Multiple Criteria in Excel COUNTIF Function - less Than

You can also have the criteria in a cell and use the cell reference as the criteria. In this case, you need NOT put the criteria in double quotes (see pic below):

=COUNTIF($B$2:$B$11,D3)

Excel COUNTIF Function with multiple criteria - Less Than criteria in cell reference

Also, there could be a case when you want the criteria to be in a cell, but don’t want it with the operator. For example, you may want the cell D3 to have the number 5 and not <5.

In that case, you need to create a criteria argument which is a combination of operator and cell reference:

=COUNTIF($B$2:$B$11,”<“&D3)

Using Less Than operator in Excel COUNTIF function

NOTE: When you combine an operator and a cell reference, the operator is always in double quotes. The operator and cell reference are joined by an ampersand (&).

#4 Count Cells with Multiple Criteria – Between Two Values

To get a count of values between two values, we need to use multiple criteria in the COUNTIF function.

Here are two methods of doing this:

METHOD 1: Using COUNTIFS function

COUNTIFS function can handle multiple criteria as arguments and counts the cells only when all the criteria are TRUE. To count cells with values between two specified values (say 5 and 10), we can use the following COUNTIFS function:

=COUNTIFS($B$2:$B$11,”>5″,$B$2:$B$11,”<10″)

Using Multiple Criteria in Excel COUNTIFS Function - Between criteria

NOTE: The above formula does not count cells that contain 5 or 10. If you want to include these cells, use greater than equal to (>=) and less than equal to (<=) operators. Here is the formula:

=COUNTIFS($B$2:$B$11,”>=5″,$B$2:$B$11,”<=10″) 

You can also have these criteria in cells and use the cell reference as the criteria. In this case, you need NOT put the criteria in double quotes (see pic below):

Excel COUNTIFS Function with multiple criteria - Between criteria in cell references

You can also use a combination of cells references and operators (where the operator is entered directly in the formula). When you combine an operator and a cell reference, the operator is always in double quotes. The operator and cell reference are joined by an ampersand (&).

Excel COUNTIFS Function - Between criteria operator and cell references

METHOD 2: Using two COUNTIF functions

If you have multiple criteria, you can either use COUNTIFS or create a combination of COUNTIF functions. The formula below would also do the same thing:

=COUNTIF($B$2:$B$11,”>5″)-COUNTIF($B$2:$B$11,”>10″)

In the above formula, we first find the number of cells that have a value greater than 5 and we subtract the count of cells with a value greater than 10. This would give us the result as 5 (which is the number of cells that have values more than 5 and less than equal to 10).

Using Multiple Criteria in Excel COUNTIF Function - Between criteria two countif

If you want the formula to include both 5 and 10, use the following formula instead:

=COUNTIF($B$2:$B$11,”>=5″)-COUNTIF($B$2:$B$11,”>10″)

If you want the formula to exclude both ‘5’ and ’10’ from the counting, use the following formula:

=COUNTIF($B$2:$B$11,”>=5″)-COUNTIF($B$2:$B$11,”>10″)-COUNTIF($B$2:$B$11,10)

You can have these criteria in cells and use the cells references, or you can use a combination of operators and cells references.

Using TEXT Criteria in Excel Functions

#1 Count Cells when Criteria is EQUAL to a Specified text

To count cells that contain an exact match of the specified text, we can simply use that text as the criteria. For example, in the dataset (shown below in the pic), if I want to count all the cells with the name Joe in it, I can use the below formula:

=COUNTIF($B$2:$B$11,”Joe”)

Since this is a text string, I need to put the text criteria in double quotes.

Using Multiple Text Criteria in Excel COUNTIF Function

You can also have the criteria in a cell and then use that cell reference (as shown below):

=COUNTIF($B$2:$B$11,E3)

Using Multiple Text Criteria in Excel COUNTIFS Function

NOTE: You can get wrong results if there are leading/trailing spaces in the criteria or criteria range. Make sure you clean the data before using these formulas.

#2 Count Cells when Criteria is NOT EQUAL to a Specified text

Similar to what we saw in the above example, you can also count cells that do not contain a specified text. To do this, we need to use the not equal to operator (<>).

Suppose you want to count all the cells that do not contain the name JOE, here is the formula that will do it:

=COUNTIF($B$2:$B$11,”<>Joe”)

Using Multiple Criteria in Excel COUNTIF Function - Text criteria Not equal to

You can also have the criteria in a cell and use the cell reference as the criteria. In this case, you need NOT put the criteria in double quotes (see pic below):

=COUNTIF($B$2:$B$11,E3)

Using Multiple Criteria in Excel COUNTIF Function - Text criteria Not equal cells references

There could also be a case when you want the criteria to be in a cell but don’t want it with the operator. For example, you may want the cell D3 to have the name Joe and not <>Joe.

In that case, you need to create a criteria argument which is a combination of operator and cell reference (see pic below):

=COUNTIF($B$2:$B$11,”<>”&E3)

Using Multiple Criteria in Excel COUNTIF Function - Text criteria Not equal cells references and operator

When you combine an operator and a cell reference, the operator is always in double quotes. The operator and cell reference are joined by an ampersand (&).

Using DATE Criteria in Excel COUNTIF and COUNTIFS Functions

Excel store date and time as numbers. So we can use it the same way we use numbers.

#1 Count Cells when Criteria is EQUAL to a Specified Date

To get the count of cells that contain the specified date, we would use the equal to operator (=) along with the date.

To use the date, I recommend using the DATE function, as it gets rid of any possibility of error in the date value. So, for example, if I want to use the date September 1, 2015, I can use the DATE function as shown below:

=DATE(2015,9,1)

This formula would return the same date despite regional differences. For example, 01-09-2015 would be September 1, 2015 according to the  US date syntax and January 09, 2015 according to the UK date syntax. However, this formula would always return September 1, 2105.

Here is the formula to count the number of cells that contain the date 02-09-2015:

=COUNTIF($A$2:$A$11,DATE(2015,9,2))

Excel COUNTIF Function - Using multiple date criteria

#2 Count Cells when Criteria is BEFORE or AFTER to a Specified Date

To count cells that contain date before or after a specified date, we can use the less than/greater than operators.

For example, if I want to count all the cells that contain a date that is after September 02, 2015, I can use the formula:

=COUNTIF($A$2:$A$11,”>”&DATE(2015,9,2))

Using Multiple Criteria in Excel COUNTIF Function - Date Criteria after

Similarly, you can also count the number of cells before a specified date. If you want to include a date in the counting, use and ‘equal to’ operator along with ‘greater than/less than’ operator.

You can also use a cell reference that contains a date. In this case, you need to combine the operator (within double quotes) with the date using an ampersand (&).

See example below:

=COUNTIF($A$2:$A$11,”>”&F3)

Using Multiple Criteria in Excel COUNTIF Function - Date Criteria using cell reference and ampersand

#3 Count Cells with Multiple Criteria – Between Two Dates

To get a count of values between two values, we need to use multiple criteria in the COUNTIF function.

We can do this using two methods – One single COUNTIFS function or two COUNTIF functions.

METHOD 1: Using COUNTIFS function

COUNTIFS function can take multiple criteria as the arguments and counts the cells only when all the criteria are TRUE. To count cells with values between two specified dates (say September 2 and September 7), we can use the following COUNTIFS function:

=COUNTIFS($A$2:$A$11,”>”&DATE(2015,9,2),$A$2:$A$11,”<“&DATE(2015,9,7))

Using Multiple Criteria in Excel COUNTIF Function - Date Criteria before and after

The above formula does not count cells that contain the specified dates. If you want to include these dates as well, use greater than equal to (>=) and less than equal to (<=) operators. Here is the formula:

=COUNTIFS($A$2:$A$11,”>=”&DATE(2015,9,2),$A$2:$A$11,”<=”&DATE(2015,9,7))

You can also have the dates in a cell and use the cell reference as the criteria. In this case, you can not have the operator with the date in the cells. You need to manually add operators in the formula (in double quotes) and add cell reference using an ampersand (&). See the pic below:

=COUNTIFS($A$2:$A$11,”>”&F3,$A$2:$A$11,”<“&G3)

Using Multiple Criteria in Excel COUNTIF Function - Date Criteria before and after cell reference

METHOD 2: Using COUNTIF functions

If you have multiple criteria, you can either use one COUNTIFS function or create a combination of two COUNTIF functions. The formula below would also do the trick:

=COUNTIF($A$2:$A$11,”>”&DATE(2015,9,2))-COUNTIF($A$2:$A$11,”>”&DATE(2015,9,7))

Using Multiple Criteria in Excel COUNTIF Function - Date Criteria before and after using countif without equal to

In the above formula, we first find the number of cells that have a date after September 2 and we subtract the count of cells with dates after September 7. This would give us the result as 7 (which is the number of cells that have dates after September 2 and on or before September 7).

If you don’t want the formula to count both September 2 and September 7, use the following formula instead:

=COUNTIF($A$2:$A$11,”>=”&DATE(2015,9,2))-COUNTIF($A$2:$A$11,”>”&DATE(2015,9,7))

Using Multiple Criteria in Excel COUNTIF Function - Date Criteria before and after using countif

If you want to exclude both the dates from counting, use the following formula:

=COUNTIF($A$2:$A$11,”>”&DATE(2015,9,2))-COUNTIF($A$2:$A$11,”>”&DATE(2015,9,7)-COUNTIF($A$2:$A$11,DATE(2015,9,7)))

Also, you can have the criteria dates in cells and use the cells references (along with operators in double quotes joined using ampersand).

Using WILDCARD CHARACTERS in Criteria in COUNTIF & COUNTIFS Functions

There are three wildcard characters in Excel:

  1. * (asterisk) – It represents any number of characters. For example, ex* could mean excel, excels, example, expert, etc.
  2. ? (question mark) – It represents one single character. For example, Tr?mp could mean Trump or Tramp.
  3. ~ (tilde) – It is used to identify a wildcard character (~, *, ?) in the text.

You can use COUNTIF function with wildcard characters to count cells when other inbuilt count function fails. For example, suppose you have a data set as shown below:

Count Cells that Contains Text in Excel Data Set

Now let’s take various examples:

#1 Count Cells that contain Text

To count cells with text in it, we can use the wildcard character * (asterisk). Since asterisk represents any number of characters, it would count all cells that have any text in it. Here is the formula:

=COUNTIFS($C$2:$C$11,”*”)

Using Multiple Criteria in Excel COUNTIF Function - wildcard character count text

Note: The formula above ignores cells that contain numbers, blank cells, and logical values, but would count the cells contain an apostrophe (and hence appear blank) or cells that contain empty string (=””) which may have been returned as a part of a formula.

Here is a detailed tutorial on handling cases where there is an empty string or apostrophe.

Here is a detailed tutorial on handling cases where there are empty strings or apostrophes.

Below is a video that explains different scenarios of counting cells with text in it.

#2 Count Non-blank Cells

If you are thinking of using COUNTA function, think again.

Try it and it might fail you. COUNTA will also count a cell that contains an empty string (often returned by formulas as =”” or when people enter only an apostrophe in a cell). Cells that contain empty strings look blank but are not, and thus counted by the COUNTA function.

COUNTA will also count a cell that contains an empty string (often returned by formulas as =”” or when people enter only an apostrophe in a cell). Cells that contain empty strings look blank but are not, and thus counted by the COUNTA function.

Count Cells that Contains Text in Excel Data Set

So if you use the formula =COUNTA(A1:A11), it returns 11, while it should return 10.

Here is the fix:

=COUNTIF($A$1:$A$11,”?*”)+COUNT($A$1:$A$11)+SUMPRODUCT(–ISLOGICAL($A$1:$A$11))

Let’s understand this formula by breaking it down:

#3 Count Cells that contain specific text

Let’s say we want to count all the cells where the sales rep name begins with J. This can easily be achieved by using a wildcard character in COUNTIF function. Here is the formula:

=COUNTIFS($C$2:$C$11,”J*”) 

Using Multiple Criteria in Excel COUNTIF Function - count specific text wildcard

The criteria J* specifies that the text in a cell should begin with J and can contain any number of characters.

If you want to count cells that contain the alphabet anywhere in the text, flank it with an asterisk on both sides. For example, if you want to count cells that contain the alphabet “a” in it, use *a* as the criteria.

This article is unusually long compared to my other articles. Hope you have enjoyed it. Let me know your thoughts by leaving a comment.

You May Also Find the following Excel tutorials useful:

  • Count the number of words in Excel.
  • Count Cells Based on Background Color in Excel.
  • How to Sum a Column in Excel (5 Really Easy Ways)

As the name suggests Excel COUNTIF Function is a combination of Count and IF formula. In plain English, COUNTIF Function can be described as a formula that can be used for counting the number of cells that fulfill a particular condition, within a predefined range.

How Excel Defines COUNTIF Function

Microsoft Excel defines COUNTIF as a formula that, “Counts the number of cells within a range that meet the given condition”.

This definition clearly explains that: COUNTIF Function is a better and sophisticated type of COUNT formula that gives you control over, which cells you wish to count.

Syntax of Excel COUNTIF Formula

Excel COUNTIF formula can be written as follows:

=COUNTIF(range , criteria)

Here ‘range’ specifies the range of cells over which you want to apply the ‘criteria‘.

criteria’ specifies the condition that a particular cell content should meet to be counted.

How to Use COUNTIF in Excel

Now, let’s see how to use the COUNTIF function in Excel.

Let’s consider, we have an Employee table as shown in the below image.

Employee Table

Objective: From the above table, our objective is to find the number of employees who have joined before 1990.

So, we will try to use the COUNTIF Formula to find the result.

Using Countif 01

range: In this case, ‘range’ will be “B2:B11”, as on these cells we have to apply the ‘criteria’.

Using CountIf 02

criteria: In this case, ‘ criteria’ is “<01/01/1990”. This specifies that we want to count only those employees that are joined before 1st January 1990.

Result of CountIf

This results in 6, which means there are 6 employees that have joined before 1990.

Few Important Facts About the COUNTIF Formula

1. COUNTIF formula only accepts a solid range, you cannot give multiple broken ranges to it. For example, COUNTIF cannot be written as

=COUNTIF(A1:A4 , A6:A8, ">0") //This is wrong
=COUNTIF(A1:A8, ">0") //This is correct

2. COUNTIF can accept wildcard characters (like “*” and “?”) in the ‘criteria’ argument. This means that you can write a COUNTIF as

=COUNTIF(D1:D15, "*o*")

This will count all the cells containing the “o” character, within the D1:D5 range.

3. As you know, the output of COUNTIF is an integer so you can also add two COUNTIF functions. For example: if you want to find the cells with value as “1” and cells with value as “2”, so you can use COUNTIF as

=COUNTIF(A1:A10,"1")+COUNTIF(A1:A10,"2")

4. COUNTIF throws a #NAME? error, if you supply an incorrect range to it.

Few Basic Examples of COUNTIF Function

Excel COUNTIF Function

In the above image, I have used an Employee table to depict how the COUNTIF function can be used.

Example 1: In the first example, I have used the Excel COUNTIF formula for finding the number of employees whose first name starts with “G”.

For this, I have used formula as

=COUNTIF(A3:A12,"G*")

Here, the COUNTIF Function scans the whole range from A3:A12 and tries to find a pattern “G*” (‘*’ is a wildcard operator which denotes any number of characters). The resultant is 2, as there are only two persons in the specified range whose first name starts with G.

Example 2: In the second example, I have used a COUNTIF function to find the cells which contain an Employee ID value greater than “26000”.

To accomplish this I have used a formula

=COUNTIF(C3:C12,">26000")

This formula searches the specified range for a value that specifies the criteria (i.e. >26000). So, the result is 5 as only 5 employees have an Employee ID greater than 26000.

Example 3: In the third example, I have fetched the number of employees whose salary is less than 4000.

To get this, I have again used a COUNTIF formula as

=COUNTIF(D3:D12,"<4000")

So, here the COUNTIF counts only those cells where salary range i.e. D3:D12 has a value less than 4000 and the resultant is 3.

Example 4: In the fourth example, I have used the following  formula

=COUNTIF(B3:B12,B5)

This formula finds the number of cells equal to the value of the cell B5 (i.e. “Massiot”), in the range B3:B15.

Here, first, the COUNTIF function finds the value at the B5 cell, and then it compares all the cells within the specified range with this value.

The resultant is 2 as only two records match the value at the B5 cell.

Excel COUNTIF Function Addition

Example 5: In the above example, I had to find the total count of cells that contain “Apple” or “Peach”.

This can be easily done by adding the resultants of two COUNTIF statements like:

=COUNTIF(A2:A7,"Apple")+COUNTIF(A2:A7,"Peach")

The first COUNTIF statement gives the number of cells with a value equal to “Apple” and the second statement gives the count of cells with “Peach”. And hence the output comes out as 2+1=3.

Example 6: In this example (i.e. =COUNTIF(A,"Pear")), I have tried to show you what happens if you enter an incorrect range in the COUNTIF function.

In such cases, it throws a #NAME? error.

Few Advanced Examples of COUNTIF Function

Now, let’s see some practical examples of COUNTIF Function.

Example 7: Finding duplicate values using the COUNTIF function.

Let’s say we have a table as below, and we have to find the duplicate records in it.

Find Duplicates Using CountIF

For finding the duplicate records, we have used the formula:

=COUNTIF($A$2:$A$16,A2)>1

When this formula encounters a duplicate record it returns TRUE, while FALSE means that the record is Unique.

Find Duplicates using CountIF 02

If you are wondering what these dollar ($) signs are doing in this formula, then you should read this post.

Recommended Reading: Find and Delete Duplicate cells in Excel

Example 8: Use the COUNTIF formula for generating the sorting order of a list.

Let’s consider we have a list as below.

Use Countif to find the Sorting order of a list

Now, If we just want to know the alphabetic sorting order (in ascending order) of the employee names, then we can use the formula:

=COUNTIF($A$2:$A$15,"<="&A2)

See the below image, to see this formula in action.

Use Countif to find the Sorting order of a list 02

As you can see, that this formula generates a number in-front of every employee. This number is the sorting order (in ascending sort) of the Employee Names.

Recommended Reading: How to alphabetize a list in Excel

So, this was all from my side. Do share your ideas and experiences related to Excel COUNTIF Function in the below comments section.

The COUNTIF function of excel just counts the number of cells with a specific condition in a given range.
1
Syntax Of COUNTIF Statement

=COUNTIF(range, condition)

Range: it is simply the range in which you want to count values.

Condition: This is where we tell Excel what to count. It can be a specific Text (should be in “”), a number, a logical operator(=,><,>=,<=,<>) and wild card operators (*,?).

Let’s understand COUNTIF Statement with some easy examples

COUNTIF to Count Text

Note: COUNTIF is not case sensitive. A and a, both are treated equally.
To count a specific text in range in excel, always use double quotes (“”). I have this data in a spread sheet.

2

In range A1:D13 i have my data. Now one query has arrived. How many times did Thanos win? In column B I have names of winners.
So in cell G2 I write this excel COUNTIF formula:

=COUNTIF(B2:B13,»Thanos»)

The formula will return a number of times Thanos appears in the range of B2:B13.
3

COUNTIF to Count Numeric Values

You don’t need to use double quotes (“”) to count numeric values. Let’s see an example first.
Now, after the first query, another query appears. How many times have there been 0 prices?
4
To answer this, I wrote this COUNTIF formula in cell G3.

=COUNTIF(C2:C13,0)

And it returns 2. Because the price is in Range C2:C13, I used it in range.
5

COUNTIF to Count Numbers with Conditions

After answering the last query, I got another query, i.e. How many times was the price more than 50 Rs?
So now we need to count all values that are greater than 50.
6
While using numeric operators (=,>,<,>=,<=,<>) you need to use double quotes.
So now in cell G3, I wrote this COUNTIF formula:

=COUNTIF(C2:C13,»>50″)

It returns 5. Notice the double quote. Now, if your condition value was in some other cell, say in E4 than you would write:

=COUNTIF(C2:C13,»>”&E4)

Either way, the result will be the same.
7

COUNTIF with Wild Card Operators (*,?)

USE of * Operator In Excel COUNTIF FUNCTION

We have another query here. How many times have there been gold winners? Now it is mentioned in D. But it contains the names of the winners too.
8
If you write COUNTIF(D2:D13,”Gold”). It will return 0. Because no cell contains Gold according to excel. But it does. To tell Excel to count any value that ends with Gold, we would write this COUNTIF formula in cell G5:

=COUNTIF(D2:D13,»*Gold»)

I will return the correct value which is 3
9
Now the COUNTIF if function counts every value that ends with gold. The * operator just accepts anything written before Gold. If you write *Gold*, then COUNTIF will count anything that contains Gold in it.

USE of ? Operator COUNTIF FUNCTION

The ? operator is used when you know how many letters there are, but you don’t know exactly what they are. For example, if I want to count all the Delhi pin numbers from a range, then I know they start at 1100 and are in total 6 digits. So my search criteria will be “1100??”.
Try this one by yourself and let me know what you found. Use the comments section below to ask questions and give suggestions. They are highly appreciated.

Related Articles:

How to Count Unique Values In Excel

How to use COUNTIFS with Dynamic Criteria Range in Excel

How to use COUNTIFS Two Criteria Match in Excel

COUNTIFS With OR For Multiple Criteria in Excel

How to use the COUNTIFS Function in Excel

How to Use Countif in VBA in Microsoft Excel

Popular Articles:

50 Excel Shortcuts to Increase Your Productivity

How to use the VLOOKUP Function in Excel

How to use the SUMIF Function in Excel

The COUNTIF function counts cells in a range that meet a given condition, referred to as criteria. COUNTIF is a common, widely used function in Excel, and can be used to count cells that contain dates, numbers, and text. Note that COUNTIF can only apply a single condition. To count cells with multiple criteria, see the COUNTIFS function.

Syntax

The generic syntax for COUNTIF looks like this:

=COUNTIF(range,criteria)

The COUNTIF function takes two arguments, range and criteria. Range is the range of cells to apply a condition to. Criteria is the condition to apply, along with any logical operators that are needed.

Applying criteria

The COUNTIF function supports logical operators (>,<,<>,<=,>=) and wildcards (*,?) for partial matching. The tricky part about using the COUNTIF function is the syntax used to apply criteria. COUNTIFS is in a group of eight functions that split logical criteria into two parts, range and criteria. Because of this design, each condition requires a separate range and criteria argument, and operators in the criteria must be enclosed in double quotes («»). The table below shows examples of the syntax needed for common criteria:

Target Criteria
Cells greater than 75 «>75»
Cells equal to 100 100 or «100»
Cells less than or equal to 100 «<=100»
Cells equal to «Red» «red»
Cells not equal to «Red» «<>red»
Cells that are blank «» «»
Cells that are not blank «<>»
Cells that begin with «X» «x*»
Cells less than A1 «<«&A1
Cells less than today «<«&TODAY()

Notice the last two examples involve concatenation with the ampersand (&) character.  Any time you are using a value from another cell, or using the result of a formula in criteria with a logical operator like «<«, you will need to concatenate. This is because Excel needs to evaluate cell references and formulas first to get a value, before that value can be joined to an operator.

Basic example

In the worksheet shown above, the following formulas are used in cells G5, G6, and G7:

=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, «CA» and «ca» are treated the same.

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

Not equal to

To construct «not equal to» criteria, use the «<>» operator surrounded by double quotes («»). For example, the formula below will count cells not equal to «red» in the range A1:A10:

=COUNTIF(A1:A10,"<>red") // not "red"

Blank cells

COUNTIF can count cells that are blank or not blank. The formulas below count blank and not blank cells in the range A1:A10:

=COUNTIF(A1:A10,"<>") // not blank
=COUNTIF(A1:A10,"") // blank

Note: be aware that COUNTIF treats formulas that return an empty string («») as not blank. See this example for some workarounds to this problem.

Dates

The easiest way to use COUNTIF with dates is to refer to a valid date in another cell with a cell reference. For example, to count cells in A1:A10 that contain a date greater than the date in B1, you can use a formula like this:

=COUNTIF(A1:A10, ">"&B1) // count dates greater than A1

Notice we must concatenate an operator to the date in B1. To use more advanced date criteria (i.e. all dates in a given month, or all dates between two dates) you’ll want to switch to the COUNTIFS function, which can handle multiple criteria.

The safest way to hardcode a date into COUNTIF is to use the DATE function. This ensures Excel will understand the date. To count cells in A1:A10 that contain a date less than April 1, 2020, you can use a formula like this

=COUNTIF(A1:A10,"<"&DATE(2020,4,1)) // dates less than 1-Apr-2020

Wildcards

The wildcard characters question mark (?), asterisk(*), or tilde (~) can be used in criteria. A question mark (?) matches any one character and an asterisk (*) matches zero or more characters of any kind. For example, to count cells in A1:A5 that contain the text «apple» anywhere, you can use a formula like this:

=COUNTIF(A1:A5,"*apple*") // cells that contain "apple"

To count cells in A1:A5 that contain any 3 text characters, you can use:

=COUNTIF(A1:A5,"???") // cells that contain any 3 characters

The tilde (~) is an escape character to match literal wildcards. For example, to count a literal question mark (?), asterisk(*), or tilde (~), add a tilde in front of the wildcard (i.e. ~?, ~*, ~~).

OR logic

The COUNTIF function is designed to apply just one condition. However, to count cells that contain «this OR that», you can use an array constant and the SUM function like this:

=SUM(COUNTIF(range,{"red","blue"})) // red or blue

The formula above will count cells in range that contain «red» or «blue». Essentially, COUNTIF returns two counts in an array (one for «red» and one for «blue») and the SUM function returns the sum. For more information, see this example.

Limitations

The COUNTIF function has some limitations you should be aware of:

  • COUNTIF only supports a single condition. If you need to count cells using multiple criteria, use the COUNTIFS function.
  • COUNTIF requires an actual range for the range argument; you can’t provide an array. This means you can’t alter values in range before applying criteria.
  • COUNTIF is not case-sensitive. Use the EXACT function for case-sensitive counts.
  • COUNTIFS has other quirks explained in this article.

The most common way to work around the limitations above is to use the SUMPRODUCT function. In the current version of Excel, another option is to use the newer BYROW and BYCOL functions.

Notes

  • Text strings in criteria must be enclosed in double quotes («»), i.e. «apple», «>32», «app*»
  • Cell references in criteria are not enclosed in quotes, i.e. «<«&A1
  • The wildcard characters ? and * can be used in criteria. A question mark matches any one character and an asterisk matches any sequence of characters (zero or more).
  • To match a literal question mark(?) or asterisk (*), use a tilde (~) like (~?, ~*).
  • COUNTIF requires a range, you can’t substitute an array.
  • 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.
Skip to content

How to Use COUNTIF in Excel: Step-by-Step (+COUNTIFS)

How to Use COUNTIF in Excel: Step-by-Step (+COUNTIFS)

The Excel COUNTIF function is a very smart mix of the COUNT and IF functions of Excel.

Using this function you can count cells that meet a specified condition. And as it’s you who’s going to define the condition – so you have the world open to you 🛫

And if you have more than one condition to define, you can use the COUNTIFS function. How to use both of these functions?

I will walk you through that with a lot of examples (literally a lot of them) in the guide below. So download our free sample workbook for this article here and dive in straight 📩

How to use the COUNTIF function

First question first, how do you use the basic COUNTIF function? The example below will teach you that.

The image hereunder has a list of different numbers.

List of different numbers

I want to know how many 50s does this have? To find that:

  1. Begin writing the COUNTIF function as follows;

=COUNTIF(

Writing the COUNTIF function
  1. Write the first argument (range) of the COUNTIF function. This is the range that contains the cells to be counted.

In our example, this is Cell range A2:A8 🎯

= COUNTIF (A2:A8

The number of cells to be counted
  1. Next, write the logical criteria argument (the IF condition) based on which the cells must be counted.

We only want to count those cells that contain 50. So our condition must be something equal to 50 (“=50”).

=COUNTIF(A2:A8, “=50”)

Writing the COUNTIF function

The criteria for COUNTIF must be enclosed in double quotation marks.

Kasper Langmann, Microsoft Office Specialist
  1. Hit Enter 🚀

Excel will now check each cell of the range A2:A8 against the specified criteria (is it equal to 50). And give results as below:

COUNTIF results in the count

We have 3 cells in the given range that are equal to 50. That’s how the COUNTIF function counts cells 💪

COUNTIFS: COUNT with multiple criteria

COUNTIFS is an advanced version of the COUNT function. Or you may call it the COUNT function with multiple criteria.

Under the COUNTIFS function, you can specify up to 127 criteria. And Excel will evaluate each value from a criteria range against the criteria for it 🔎

The COUNTIFS function works with the AND logic. It will only count the cells that meet all the conditions specified by you.

Kasper Langmann, Microsoft Office Specialist

Here is again a list of numbers. But this time, let’s find out the cells containing numbers that are greater than 50 but smaller than 50.

55 > Numbers > 50

So let’s go:

  1. Write the COUNTIFS function as follows:

= COUNTIFS (

Writing the COUNTIFS function
  1. Write the first argument (criteria_range1) of the COUNTIF function. This is the range for the first criterion.

Our first criterion is greater than 50. Excel would check the numbers against this criterion, so our first criteria range is Cell range A2:A8 👀

= COUNTIFS (A2:A8

The criteria range from 1
  1. Next, write the first criteria. Excel will check the first criteria range against this criterion.

Our first criterion is greater than 50, so we are going to write it like that “>50”.

=COUNTIF(A2:A8, “>50”

Writing the first criteria range
  1. Define the second criteria range.

Our second criterion is lesser than 55. So our criteria range is still the same.

= COUNTIFS (A2:A8, “>50”, A2:A8,

The criteria range from 2
  1. Define the second criterion (the criteria range 2 will be checked for it).

The second criterion in our example is smaller than 55 so, we are going to write it like that “<55”.

= COUNTIFS (A2:A8, “>50”, A2:A8, “<55”)

Writing the second criterion

Under the COUNTIFS function, the first criteria range and criteria are required. The rest of the arguments are optional and can be omitted 📍

Kasper Langmann, Microsoft Office Specialist
  1. Hit Enter.

Excel will now check each cell reference of the range A2:A8 against both criteria (greater than 50 and smaller than 55).

COUNTIFS returns the result

And there are only 2 of them. Superb 💥

COUNTIF and COUNTIFS formula examples

The COUNTIF and COUNTIFS functions are way more versatile than that and we are going to see that through the examples below.

Count if greater than or less than a number

You can use the COUNTIF function with greater than (>) or less than (<) operators very simply.

We’ll do that just now. Peek into the data below that has a list of people with different heights.

People and their heights

Let’s quickly use the COUNTIF function to find the number of people who are taller than 5 feet 🕺

  1. Write the COUNTIF function as follows;

= COUNTIF (B2:B8

The cell range of the COUNTIF

As the first argument (range), we have referred to the cell range that contains heights.

  1. Next, write the criteria based on which the cells must be counted.

We only want to count on those people who are taller than 5 feet. Yes, you guessed that right.

The criteria would be defined using the greater than (>) logical operator as “>5”.

=COUNTIF(B2:B8, “>5”)

The logical criteria
  1. Hit Enter.
COUNTIF results in the count

We have 5 members whose height exceeds 5 feet.

And if we want to know the number of people who are shorter than 5.5 feet 🤔

  1. Write the COUNTIF formula using the less than operator as below:

=COUNTIF(B2:B8, “<5.5”)

COUNTIF function for less than
  1. Hit Enter.
COUNTIF returns the results

Only 4 of them! It is interesting to see how the COUNTIF works, isn’t it 🏆

Count if between two numbers

In the example above, we have seen people who are taller than 5 feet. And also those who are shorter than 5.5 feet.

Let’s now try to count the number of people (from the same above dataset) that are taller than 5 feet but shorter than 5.5 feet 🙈

Note that here we have two conditions to be checked simultaneously:

  • Taller than 5 feet
  • Shorter than 5.5 feet

To run the COUNT function with multiple conditions, we need to use the COUNTIFS function. So let’s go ahead with it.

  1. Write the first criteria range and the first criteria for the COUNTIFS function.

= COUNTIFS (B2:B8, “<5.5”

Criteria and criteria range 1

As the first criteria range, we have referred to the cell range that has heights (B2:B8).

We have defined the first criteria for the first criteria range as less than 5.5 i.e.“<5.5”.

  1. Write the second criteria range and the second criteria.

=COUNTIF(B2:B8, “<5.5”, B2:B8, “>5”)

Criteria and criteria range 2

The criteria range remains the same. Whereas the second criterion (taller than 5 feet) is defined as “>5”.

  1. Hit Enter, and there you go.
Result of the COUNTIFS function

The COUNTIFS function returns 2 – these must be Henry (5.3 inches tall) and William (5.4 inches tall) 🧐

Count if greater than a date

Who said COUNTIF and COUNTIFS were only meant to count numbers?

You can also use them with dates, see here 📅

The list below has meetings listed together with the dates when each of these is scheduled.

Meetings with dates

Let’s use the COUNTIF function to count the events that are scheduled before 30 June 2023.

  1. Write the COUNTIF function as follows;

= COUNTIF (B2:B8

The cell range of the COUNTIF

As the first argument (range), we have referred to the cell range that contains the dates.

  1. Write the criteria as “<30-June-2023”.

As we want to count the dates before 30 June 2023, we will use the less than operator (<).

This way Excel will count the meetings that are scheduled before 30 June 2023 📌

=COUNTIF(B2:B8, “<30-June-2023”)

Criteria as text values
  1. Hit Enter.
COUNTIF returns the count of dates

5 meetings there are! The COUNTIF function works for dates just like it does for numbers 😍

Pro Tip!

Can you use the COUNTIF function to count blank cells 🙋‍♀️

Well, certainly you can. For example, to count the blank cells A1 to A5, write the COUNTIF function below:

= COUNTIF (A1:A5, “”)

The answer to this will be 5 ✌ That’s because we have set the criteria blank. Excel will see if all the cells are blank and count them.

Similarly, you can use the COUNTIF function together with wildcard characters (asterisk matches, question mark matches, etc.) to perform partial matches.

Count if between two dates

We have seen the simple application of the COUNTIF function with dates. But what if you want to perform a count of dates that fall between two dates?

For the same meetings as above, let’s say this time we want to count the meetings scheduled before 30 June 2023 but after 28 February 2023.

These are two conditions 👇

  • Before 30 June 2023 (<30-June-2023)
  • After 28 February 2023 (>28-February-2023)

For multiple criteria, we need to use the COUNTIFS function. So let’s go.

  1. Write the first criteria range and the first criteria for the COUNTIFS function.

= COUNTIFS (B2:B8, “<30-June-2023”

Criteria and criteria range 1

As the first criteria range, we have referred to the cell range that has dates (B2:B8).

And the first criteria will be before 30 June 2023 (in terms of logical operators “<30-June-2023”).

  1. Write the second criteria range and the second criteria.

The criteria range remains the same (Cell B2:B8). However, the second criterion will be “>28-February-2023” 👩‍🏫

To count the dates that fall after 28 February 2023, we will use the greater than operator (>).

=COUNTIFS(B2:B8, “<30-June-2023”, B2:B8, “>28-February-2023”)

Criteria and criteria range 2
  1. Hit Enter to see what Excel has got for us.
COUNTIFS returns the count of dates

Excel says there are 3 meetings between 28th February and 30th June 2023 3️⃣

And guess what, that’s right.

  • Meeting No. 1 on 31 May 2023;
  • Meeting No. 2 on 25 March 2023; and
  • Meeting No. 7 on 04 April 2023.

That’s it – Now what?

That’s all about the two bombastic and very commonly used logical functions of Excel – the COUNTIF and COUNTIFS functions 🥈

Both of them are lifesavers. You can use them to sort and evaluate your rows-long Excel data in seconds. And just like these two functions, the Excel function library is a whole pack of amazing functions.

To learn Excel functions, we suggest you start from the core Excel functions like the VLOOKUP, SUMIF, and IF functions. How?

Enroll in my 30-minute free email course to learn these (and many more) functions of Excel now.

Frequently asked questions

To perform a COUNTIF with multiple criteria, use the COUNTIFS function.

Under the COUNTIFS function, you can specify up to 127 criteria. The syntax of the COUNTIFS function is as follows:

=COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2…)

The COUNTIFS function allows users to perform a count across multiple cell ranges based on single or multiple conditions.

It works on the AND logic and will only count those cells that meet all the specified criteria.

The syntax of the COUNTIFS function is as follows:

= COUNTIFS (criteria_range1, criteria1, criteria_range2, criteria2…)

You can specify up to 127 criteria under the COUNTIFS function.

Kasper Langmann2023-01-27T17:33:51+00:00

Page load link

COUNTIF Formula in Excel

Excel COUNTIF Formula (Table of Contents)

  • COUNTIF Formula in Excel
  • How to Use COUNTIF Formula in Excel?

COUNTIF Formula in Excel

COUNTIF Formula in excel is an inbuilt or pre-built integrated function which is categorized under the statistical group of formulae.

Excel COUNTIF Formula counts the number of cells within a specified array or range based on a specific criterion or applied condition.

Below is the Syntax of the COUNTIF Formula in Excel :

COUNTIF Formula

The COUNTIF Formula in Excel has two arguments, i.e. range, criteria.

  1. Range: (Required & Compulsory argument): The range or array of cells on which the criteria should be applied, here array or range should be mentioned as, e.g. C1:C12.
  2. Criteria: (Required & Compulsory argument)) It is a specific condition which will be applied to the cell values presented by the range of cells. It indicates the Count IF formula “what cells need to be counted” here. There is a limitation of the criteria argument in the COUNTIF Formula, i.e. If the text string in the criteria argument contains greater than 255 characters in length or more than 255 characters. Then it returns #VALUE! error.

Note: It can be either a cell reference or text string or logical or mathematical expression.

  • A named range can also be used in the COUNTIF formula.
  • In the Criteria argument, Non-numeric values compulsorily should always be enclosed within double-quotes.
  • Criteria argument is case-insensitive, where it can consider any text case, it may be proper or upper or lower case.
  • In the Excel COUNTIF formula, the below-mentioned arithmetic operators can also be used in the criteria argument

=             Equal to
<             Less Than
<=          Less than or equal to
>             Greater Than
>=          Greater than or equal to
<>          Less than or greater than

How to Use COUNTIF Formula in Excel?

COUNTIF Formula in Excel is very simple and easy to use. Let’s understand the working of the COUNTIF Formula in Excel with some examples.

You can download this COUNTIF Formula Excel Template here – COUNTIF Formula Excel Template

Excel COUNTIF Formula – Example #1

In the following example, the Table contains company employees name in column A (A2 to A15) & funds transferred status in column B (B2 to B15). Here I need to find out the count of two parameters, i.e. funds transferred & funds not transferred in the dataset range (B2 to B15).

Example 1

  • Let’s apply the COUNTIF function in cell D4. Select cell D4 where the COUNTIF formula needs to be applied.

COUNTIF Formula Example 1-2

  • Click or select an Insert Function (fx) button in the formula toolbar; a dialog box will appear, where you need to enter or type the keyword countif in the Search for a function box, COUNTIF formula will appear in select a function box. Double click on the COUNTIF formula.

COUNTIF Formula Example 1-3

  • A function argument dialog box appears where syntax or arguments for the COUNTIF formula needs to be entered or filled. i.e. =COUNTIF (Range, Criteria)

COUNTIF Formula Example 1-4

  • Range: It is a range of cells where you want to count. Here the range or array is from B2 to B15, So select the column range. i.e. B2:B15

COUNTIF Formula Example 1-5

  • Criteria: It is a condition or criteria where you insert the COUNTIF function, which cells need to be counted, i.e. “Y” (here, we need to find out the count of an employee who has received a number of funds). Click OK after entering both range & criteria argument. =COUNTIF (B2:B15,”Y”)

COUNTIF Formula Example 1-6

  • COUNTIF formula returns the count of an employee who has received fund, i.e. from the dataset range (B2:B15). Here, the COUNTIF formula returns a count. within a defined range. It means eight number of employees have received funds.

Result of Example 1-1

  • Suppose I want to find out the number or count of employees who have not received funds. Just I need to change the criteria argument, i.e. instead of “Y”, I need to use “N” =COUNTIF (B2:B15,”N”)

COUNTIF Formula Example 1-8

  • COUNTIF formula returns the count of an employee who has not received a fund, i.e. from the dataset range (B2:B15). Here, the COUNTIF formula returns a count of within a defined range. It means six number of employees who haven’t received funds.

Result of Example 1-2

Excel COUNTIF Formula – Example #2

With Arithmetic Operator in criteria argument

In the second example, the Table contains students name in column A (A2 to A15), Total marks scored in column B (B2 to B15) and their percentage in column C (C2 to C15); here, I need to find out the count or number of students who have scored more than or equal to 90% in a dataset range (C2 to C15).

Example 2

  • Now, we can apply the COUNTIF formula with an arithmetic operator in the cell E3. i.e. =COUNTIF (Range, criteria)

COUNTIF Formula Example 2-2

  • Range: It is a range of cells where you want to count. Here the range or array is from C2 to C15, So select the column range. i.e. C2:C15.

COUNTIF Formula Example 2-3

  • Criteria: It is a condition or criteria where you inform the count of function, which cells need to be counted, i.e. “>=90%” (Here I need to find out the count or number of Students who has scored more than or equal to 90% in a dataset range (C2 to C15)).

COUNTIF Formula Example 2-4

  • Here, the =COUNTIF (C2:C15,”>=90%”) formula returns a value 3, i.e. No of Students who have scored more than or equal to 90% in a dataset range (C2 to C15).

Result of Example 2

Things to Remember About COUNTIF Formula in Excel

The Wildcard characters can also be used in the excel COUNTIF formula (in criteria argument) to get the desired result; Wildcards helps out in partial matching.

The three most commonly & widely used wildcard characters in the Excel COUNTIF formula are

  • Asterisk (*): To match any sequence of either trailing or leading characters. E.g. Suppose if you want to match all cells in a range containing a text string beginning with the letter “T” and ending with the letter “e”, You can enter the condition or criteria argument as “T*e”.
  • tilde (~): To find an actual question mark or asterisk. E.g. Suppose if you want to match all the cells in a range containing Asterisk (*) or Question mark (?) in the text, then tilde (~) is used in condition or criteria argument as “*~*shirt*” E.g. Red*shirt Green shirt.

In the above example, it will track the Red*shirt because it contains Asterisk (*) character in between

Asterisk (*) usage examples

TOR* Finds the text containing or Starting with TOR

*TOR Finds the text containing or Ending with TOR

*TOR* Finds the text Containing the word TOR

  • Question mark (?): Used to identify or track any single character. e.g. Suppose if you want to track “shirts” word or words ending with “S” in the below-mentioned example, then in the criteria argument, I need to use “shirt?”, it will result in the value 1.

Redshirts

Green shirt

Recommended Articles

This has been a guide to COUNTIF Formula in excel. Here we discuss how to use COUNTIF Formula in excel along with practical examples and a downloadable excel template. You can also go through our other suggested articles –

  1. COUNTIF with Multiple Criteria
  2. COUNTIF Examples in Excel
  3. Count Characters in Excel
  4. COUNTIF Excel Function

Понравилась статья? Поделить с друзьями:
  • Excel count if not value
  • Excel desktop что это
  • Excel count if not in range
  • Excel count if it contains
  • Excel delphi формула если