How to do countif in excel

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

Excel tables with their functions come in handy to count cells with data, horizontally and vertically. COUNTIF is the common function for counting cells with one and several conditions. So let’s look into this further to understand all the details and distinctions.

Meaning of COUNTIF Excel

COUNTIF in Excel is a statistical function that counts cells with those data that users indicate. It takes into account one condition. 

  • You can find items recorded even for months under a specific name. 
  • You may count the number of cells that hold a common letter or sign. 
  • You can use the Excel COUNTIF not blank to learn the empty cells quantity.
  • You specify numerosity more or less than a mentioned value.

The COUNTIF formula in Excel consists of range (which goes first) and criteria (indicates the corresponding position). 

=COUNTIF (range, criterion) 
  • range is the mandatory argument, which includes cells needed to find. 
  • criterion includes expression, word, figures, letter, or other conditions that you need to discover.

How to use COUNTIF in Excel?

The function works with only one condition. Nevertheless, a person may single out many different data in turn. The computation is carried out with numbers, letters, words, phrases and dates. You can only write a cell reference or an entire condition. Sometimes, wildcards and symbols assist to determine more accurate values.

How COUNTIF works in Excel?

The function calculates the number of cells with indicated context, i.e., with the data that the user needs to count. For instance, you have a chart with diversified furniture bought over time. You may count what furniture (sofa, bed, wardrobe, chair, table, etc.) people buy. The COUNTIF will compute the cells in which the mentioned furniture is located. You write down the formula according to the condition you ought to detect. For example, let’s count the number of cells containing the word ‘chair‘:

=COUNTIF(A1:A21,"Chair")

1 countif function example

Does COUNTIF function in Excel work for several criteria?

The COUNTIF doesn’t support frequentative conditions. Thus, you won’t find the number of chairs or nightstands purchased only in January or only on February 3. You have to use COUNTIFS for such cases.

However, you may write COUNTIF + COUNTIF. Such a COUNTIF Excel multiple criteria function makes the outcome more complete. Let’s determine the number of purchased chairs and sofas. Write the following:

=COUNTIF(A2:A21,"Chair")+COUNTIF(A2:A21,"Sofa").

2 countif function several criteria example

Samples of advanced COUNTIFS function in Excel 

COUNTIF and COUNTIFS are various functions. They differ in the computation of cells with one criterion or more criteria. The first identifies cells under one condition, and the second takes into account several specific criteria. Let’s count the number of chairs bought by Jeremy. We need to use COUNTIFS for such appointments. Write it as follows: 

=COUNTIFS(A2:A13,"Chair",B2:B13,"Jeremy")

3 advanced countifs function example

Using COUNTIF in Excel when data is on other sources

People usually store data on certain apps, such as Harvest, Google Drive, Jira, Pipedrive, etc. When you need to calculate this data in Excel, you can import it from the app. The Coupler.io tool is designed exactly for this. It will help transfer all the necessary information to BigQuery, Google Sheets, or Excel from other sources. In addition, you can automate updates to make your work easier in the future. 

1 excel integrations coupler

Sign up to Coupler.io and complete two steps to set up your Excel integration: source and destination. If you want to schedule automatic data refresh, you’ll need to configure one more step – schedule. Here is what the integration may look like:

excel integration

Practical skills based on a COUNTIF Excel example

Examine a few samples of use in more detail. Take, for instance, the furniture in the store. Imagine the owner created an Excel table regarding sales. They write down the furniture in one column there. The other column contains the dates when the goods were sold. Finally, the third column contains the quantity of each product sold. So, let’s define some samples with several formulas, including dates, words and figures.

4 practical skills countif example

Excel COUNTIF: Cells are equal or not equal

Imagine that people have bought every subject several times. Let’s take, for example, 7 times. In our formula, we specify the range where to look and the figure 7. 

=COUNTIF(B1:B20,7)

5 equal countif formula example

Let’s still find the purchased furniture that isn’t equal to 5.

=COUNTIF(B1:B20,"<>5")

6 not equal countif formula example

Excel COUNTIF: cells contain words

Let’s try to work with words using the same formula. Imagine that we need to know how many tables people bought. Let’s write the following formula. 

=COUNTIF(A2:A21,"Table")

7 countif formula with words example

As a result, people bought 2 tables. You can replace the word with a cell reference

=COUNTIF(A2:A21,E2)

8 countif formula cell reference example

COUNTIF use in Excel – meaning of wildcards

We can use COUNTIF not only with words but also with special wildcards (* and ?) to generalize the condition. 

  • ? = One character.
  • * = Sequence. 

Also, you can write ~ to find symbols * or ?.

Let’s look at a simple formula 

=COUNTIF(A1:A7,"Table")

9 countif with words example

The question mark symbol ? adds one additional character. In our dataset, there are the words ‘Table‘ and ‘Tables‘ with the last letter ‘s‘. So, Table? in the formula will look for the latter option:

=COUNTIF(A1:A7,"Table?")

10 countif question mark symbol example

The asterisk symbol * adds a sequence of characters or even spaces. For instance, the following formula counts all words that start with Tab including ‘Table’ and ‘Tables’:

=COUNTIF(A1:A7,"Tab*")

11 countif asterisk symbol example

Excel COUNTIF: сells are more than or less than

Let’s find out some values using operators: >, <, <>, =. We write it next to the criterion in quotation marks. Thanks to them, we can find cells with numbers that are more or less, equal, or not equal to some value. For example, let’s count the amount of furniture that people bought more than 3 times:

=COUNTIF(B1:B20,">3")

12 countif using operator more than

Change the logical operator to count the amount of furniture that people bought less than 3 times:

=COUNTIF(B1:B20,"<3")

13 countif using operator less than

Excel COUNTIF: count cells including date

Another feature is working with dates. So, let’s imagine that the biggest purchases fall on the date of January 1. We need to know the cells’ numerosity with this data.

=COUNTIF(B2:B21,"01/01/2021")

14 countif formula with dates

What common problems should you avoid? 

Often, people face issues using the function. We seem to be doing everything right, but the Excel function COUNTIF shows the error. Look at a few situations why it occurs. For instance, you wrote the formula 

=COUNTIF(A2:A13,Chair)

15 countif problems zero results

The function has shown zero results although this is not correct. So taking a closer look, the word ‘Chair‘ should be in quotation marks. 

=COUNTIF(A2:A13,"Chair")

In another example of incorrect syntax, the formula returned #NAME?. In this case, there is a space between the range (A1:A7) and the criterion, which also has not quotation marks (Table).

16 countif problems missing characters

The correct formula should look like this

=COUNTIF(A1:A7,"Table")

Best practices in using the COUNTIF function

It is easy to make mistakes both out of ignorance and inattention. However, by applying the following tips you can avoid the common mistakes.

  • Write the wildcards (? and *) to generalize the condition.
  • The condition can only have less than 255 characters. You will see an error exceeding this limit. To exceed the limit, you can use CONCATENATE or ampersand (&).
  • The function returns the same value if the words are written in uppercase or lowercase letters. It doesn’t take into account case strings. You should rename the word if it has a different meaning.
  • Pay attention to the spelling of words and letters. The function does not differentiate case strings and doesn’t work with misspellings.

Adherence to all principles and rules and writing correct syntax will facilitate calculations without problems. The main point is to write the formula and condition correctly.

  • Piotr Malek

    Technical Content Writer on Coupler.io who loves working with data, writing about it, and even producing videos about it. I’ve worked at startups and product companies, writing content for technical audiences of all sorts. You’ll often see me cycling🚴🏼‍♂️, backpacking around the world🌎, and playing heavy board games.

Back to Blog

Focus on your business

goals while we take care of your data!

Try Coupler.io

The COUNTIF function in Excel counts the number of cells within a range based on pre-defined criteria. It is used to count cells that include dates, numbers, or text. For example, COUNTIF(A1:A10,”Trump”) will count the number of cells within the range A1:A10 that contain the text “Trump”

Syntax

The syntax of COUNTIF formula in Excel is stated as follows:

COUNTIF Formula in Excel

It accepts the following required arguments:

  • Range: It represents the range of values on which the criteria will be applied.
  • Criteria: It represents the condition that is applied to the range of values.  The values that meet the criteria are returned as a result.

The output of the COUNTIF formula is a positive number which can be zero or non-zero.

Table of contents
  • What is COUNTIF Function in Excel
    • Syntax
    • How to Use COUNTIF Function in Excel?
      • #1 – Count Values with the Given Value
      • #2 – Count Numbers with a Value Less Than the Given Number
      • #3 – Count Values with the Given Text Value
      • #4 – Count Negative Numbers
      • #5 – Count Zero Values
    • The Criteria of the COUNTIF Formula
    • Frequently Asked Questions (FAQs)
    • Video
    • Recommended Articles

How to Use COUNTIF Function in Excel?

Being a worksheet (WS) function, the COUNTIF function can be entered as a part of the cell formula. The usage of the COUNTIF function is the same in Excel and VBA (COUNTIF function VBAVBA COUNTIF is a worksheet function used to count the number of times the criteria are fulfilled in the worksheet range. The VBA code for this function is written as WorksheetFunction.CountIf.read more).

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

Let us consider some uses to understand the working of the COUNTIF excel function.

#1Count Values with the Given Value

The following table shows a list containing numerical values in the cells A2:A7. Count the given range of cells for the values matching the number “33”.

The COUNTIF function is applied to the given range of cells, and the formula is stated as follows:

“=COUNTIF (A2:A7,33)”

Here the condition applied to the formula is the number “33”.The formula checks the range of cells A2:A7 for the values matching number “33”. The range contains only one such number, which satisfies the condition. Hence the result returned by the COUNTIF function is “1”. The result is displayed in cell A8.

COUNTIF Example 1

#2 – Count Numbers with a Value Less Than the Given Number

A list of data in the cells A12:A17 is provided in the succeeding table. Count the given range of cells for the values less than “50”.

The COUNTIF function is applied to the given range of cells, and the formula is stated as follows:

“=COUNTIF(A12:A17,“<50”)”

Here the condition applied to the formula is “<50”. The COUNTIF formula checks the range of cells matching the condition, less than 50. There are only four values that are less than 50 in the range. Hence the result returned by this function is “4”. The result is displayed in cell A18.

Example 2

#3 – Count Values with the Given Text Value

A list of data in the cells A22:A27 is provided in the below table. Count the range of cells for the text value “john”.

The COUNTIF function is applied to the given range of cells, and the formula is stated as follows:

“=COUNTIF(A22:A27, “john”)”

Here the condition applied to the formula is the value “john.” The COUNTIF formula checks the range of cells matching the given condition. The given range has only one cell that satisfies the text value “john”. Hence, the result is “1” which is displayed in cell A28.

Example 3

#4 – Count Negative Numbers

A list of data in the range of cells A32:A37 is provided in the below table. Count the range of cells for negative values (that is, less than zero).

The COUNTIF function is applied to the given range of cells, and the formula is stated as follows:

“=COUNTIF(A32:A37, “<0”)”

Here the condition applied to the formula is less than zero. Now, the COUNTIF formula will identify and count the numbers with negative values in the given range. There are three such numbers in the given range. Hence, the result is “3” which is displayed in cell A38.

Example 4

#5 – Count Zero Values

A list of data in the range of cells A42:A47 is provided in the below table. Count the range of cells for the value “0”.

The COUNTIF function is applied to the given range of cells, and the formula is stated as follows:

“=COUNTIF(A42:A47,0)”

Here the condition applied to the formula is equal to “0”. Now the COUNTIF formula will identify and count the numbers with zero values. There are two zeros in the range. Hence, the result returned is “2” which is displayed in cell A48.

Example 5

The Criteria of the COUNTIF Formula

It is enclosed within double quotes if non-numeric and without quotes if numeric.

It returns the result only if the values in the cell range satisfy the given criteria.

It can be supplied with wildcard characters like “*” and “?”. The question mark matches any one of the characters, and the asterisk matches any sequence of characters.

It uses the tilde operators followed by the wildcard characters such as “~?” and “~*”.

Frequently Asked Questions (FAQs)

1. What is the COUNTIF function in Excel?

COUNTIF function allows counting of the range of cells that meets the specified criteria. It is used to count cells that contain dates, numbers, and text.
The formula is stated as follows:
“=COUNTIF(range,criteria)”
Where,
• “Range” is a required parameter that refers to the range on which the criteria will be applied.
• “Criteria” is another required parameter that represents the condition applied to the values of the range.

2. What is the syntax of the COUNTIF function in Excel for multiple criteria?

The syntax of COUNTIF function for the same range of cells (“range 1”) with multiple criteria (“criteria 1”, “criteria 2”) is as follows:
“=COUNTIF(range 1,criteria 1)+COUNTIF(range 1,criteria 2)”
In the case of counting multiple ranges of cells with multiple criteria, the COUNTIFS function can be used.

3. What is the COUNTIFS function?

COUNTIFS function is used to evaluate cells across multiple ranges, based on single or multiple conditions. It is similar to the COUNTIF, but multiple criteria are used in the formula.
The formula of the COUNTIFS is stated as follows:
“=COUNTIFS(range 1, criteria1, range 2, criteria 2… )”
Where,
• “Range” refers to the given range of cells.
• “Criteria” refers to the conditions applied to the range.

Video

Recommended Articles

This has been a guide to the COUNTIF function in Excel. In this article, we have discussed how to use COUNTIF formula along with case studies and downloadable templates. You may also look at the below useful functions in Excel –

  • How to Use Countif not Blank in Excel?The COUNTIF not blank function counts non-blank cells within a range. read more
  • Count Unique Values in ExcelIn Excel, there are two ways to count values: 1) using the Sum and Countif function, and 2) using the SUMPRODUCT and Countif function.read more
  • How to use FIND in Excel?Find function in excel finds the location of a character or a substring in a text string. In other words it finds the occurrence of a text in another text, as it gives us the position, the output returned by this function is an integer.read more
  • COUNT in Excel

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)

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.

COUNTIF function is one of the statistical functions in Excel that is a combination of COUNT and IF functions or the COUNTA function. When used in fomula, function counts the number of cells that match specific criteria or conditions in the same or multiple ranges. The COUNTIF function helps count cells containing text, numbers, or dates that meet specific criteria.

You can count cells using COUNTIF or COUNTIFS functions in Excel. The difference between COUNTIF and COUNTIFS functions is that COUNTIF is used for counting cells that meet one criterion in one range, while COUNTIFS counts cells that fulfill multiple conditions in the same or multiple ranges.

This article will demonstrate you how to use the two functions COUNTIF and COUNTIFS in Excel.

Excel COUNTIF Function

The COUNTIF function enables you to perform data counts based on a specific criterion or condition. The condition used in the function works with logical operators (<, >, <>, =, >=, <=) and wildcards characters (*, ?) for partial matching.

Syntax of COUNTIF Function

The structure of a COUNTIF function is:

=COUNTIF(range,criteria)

Parameters:

  • range – The range of cells to count.
  • criteria – The condition determines which cells should be included in count in the specified range. Criteria can be a numeric value, text, reference to a cell address or equation.

Using COUNTIF Function to Count Numeric Values

As we discussed above, the criteria (second argument) in the COUNTIF function defines the condition that tells the function which cells to count.

This function helps you count the number of cells with values that meet logical conditions such as equal to, greater than, less than, or not equal to a specified value, etc.

In the below example, the formula counts cells that contain a value equal to 5 (criteria). You can directly insert ‘5 in the formula or use reference to the cell address that has the value (cell D2 in the below example).

=COUNTIF(B2:B11,D2)

The above formula counts the number of cells in the cell range (B2:B11) that contain the value equal to the value in cell D2.

The following formula counts the cells that has value less than 5.

=COUNTIF(B2:B11,"<5")

The less than operator (<) tells the formula to count cells with a value less than ‘5’ in the range B2:B11. Whenever you use an operator in condition, make sure to enclose it double quotes (“”).

Sometimes when you want to count the cells by examining them against a criterion (value) in a cell. In such cases, make a criterion by joining an operator and a cell reference. When you do that, you need to enclose the comparison operator in double quotes (“”), and then place an ampersand (&) between the comparison operator and the cell reference.

=COUNTIF(B2:B11,">="&D2)

The picture below shows a few example formulas and their result.

Using COUNTIF Function to Count Text Values

To count cells that contain certain text strings, use that text string as the criteria argument or the cell that contains a text string. For example, in the below table, if we want to count all the cells in the range (B21:D27) with the text value in cell B21 (sam) in it, we can use the following formula:

=COUNTIF(B21:D27,B21)

As we discussed before, we could either use the text ‘sam’ directly in the formula or use a cell reference that has the criteria (B21). A text string should always be enclosed in double-quotes (“”) when it is used in a formula in excel.

=COUNTIF(B21:D27,"sam")

To count cells that do not contain a specified text, use the below formula:

=COUNTIF(B21:D27,"<>"&B21)

Make sure to enclose the ‘not equal to’ "<>" operator in double quotes.

If you are using the text ‘sam’ directly in the formula, you need to enclose the ‘<>’ operator and text string together ("<>sam") in double-quotes.

=COUNTIF(B21:D27,"<>sam")  

Using Wildcards in Excel COUNTIF Function (Partial Matching)

You can use the COUNTIF formula with wildcard characters to count cells that contain a specific word, phrase, or letters. There are three wildcard characters you can use in the Excel COUNTIF function:

  • * (asterisk) – It is used to count cells with any number of starting and ending characters/letters. (e.g., St* could mean Stark, Stork, Stacks, etc.
  • ? (question mark) – It is used to find cells with any single character. (e.g., St?rk could mean Stark or Stork.
  • ~ (tilde) – It is used to find and count the number of cells containing a question mark or asterisk character (~, *, ?) in the text.

Counting Cells Starting or Ending with Certain Characters

To count the cells that begin or end with specific text with any number of other characters in a cell, use an asterisk (*) wildcard in the second argument of the COUNTIF function.

Use these sample formula:

=COUNTIF(A1:A10,"A*") – to count cells that starts with “A”.

=COUNTIF(A19:A28,"*er") – to count number of cells that end with the characters “er”.

=COUNTIF(A2:A12,"*QLD*") – for counting the cells that contain the text “QLD” anywhere in the text string.

A ? represents exactly one character, use this wildcard in COUNTIF function below to count the number of cells that contain exactly +1 character where ‘?’ is used.

=COUNTIF(A1:A10,"Par?s")

Counting Empty and Non-Empty Cells with COUNTIF Function

The COUNTIF formula is also helpful when it comes to counting the number of empty or non-empty cells in a given range.

Count Non-Blank Cells

If you want to count only cells that contain any ‘text’ values, use the below formula. This formula considers cells with dates and numbers as empty cells and won’t include them in in the count.

=COUNTIF(A1:B12,"*")

The wildcard * matches with only the text values and returns the count of all text values in the given range.

If you want to count all non-empty cells in a given range, try this formula:

=COUNTIF(A1:B12,"<>")

Count Blank Cells

If you want to count blank cells in a certain range, use the COUNTIF function with the * wildcard character and <> operator in the criteria argument to count empty cells.

This formula counts cells that doesn’t contain any text values:

=COUNTIF(A1:B12,"<>"&"*")

Since * wildcard matches with any text value, the above formula will count all the cells not equal to *. It counts cells with dates and numbers as blanks as well.

To count all blanks (all value types):

=COUNTIF(A1:B12,"")

This function counts only empty cells in the range.

Using COUNTIF Function to Count Dates

You can count cells with dates (same as you did with number criteria) that meet a logical condition or the specified date or date in the reference cell.

To count the cells that contain the specified date (05-05-2020), we would use this formula:

=COUNTIF(B2:B10,"05-05-2020")

You can also specify a date in different formats as the criteria in the COUNTIF function like it’s shown below:

If you want to count cells that contain dates before or after a certain date, use the less than (before) or greater than (after) operators along with the specific date or cell reference.

=COUNTIF(B2:B10,">=05/05/2020")

You can also use a cell reference that contains a date by combining it with the operator (within double quotes).

To count the number of cells in the range A2:A14 with a date before the date in E3, use the below formula, where greater than (<) operator means before the date in E3.

=COUNTIF(A2:A14,"<"&E3)

A few example formulas and their result:

Count Date based on Current Date

You can combine the COUNTIF function with specific Excel’s Date functions i.e., TODAY() to count cells that have the current date.

=COUNTIF(A2:A14,">"&TODAY())

This function count all the dates from today in the range (A2:A14).

Count Dates between a Specific Date Range

If you want to count all dates between two dates, you need to use two criteria in the formula.

We can do this by using two methods: COUNTIF and COUNTIFS functions.

Using Excel COUNTIF function

You need to use two COUNTIF functions to count all the dates between the two specified dates.

To count the dates between ’09-02-2020′ and ’20-08-2021′, use this formula:

=COUNTIF(A2:A14,">09-02-2020")-COUNTIF(A2:A14,">20-08-2021")

This formula first finds the number of cells that have a date after February 2 and subtracts the count of cells with dates after August 20. Now we get the no. of cells that have dates that come after February 2 and on or before August 20 (count is 9).

If you don’t want the formula to count both February 2 and August 20, use this formula instead:

=COUNTIF(A2:A14,">09-02-2020")-COUNTIF(A2:A14,">=20-08-2021")

Just replace ‘>’ operator with ‘>=’ in the second criteria.

Using Excel COUNTIFS function

The COUNTIFS function supports multiple criteria too and unlike, COUNTIF function, it counts the cells only after all the conditions are met. If you want to count cells with all the dates between two specified dates, enter this formula:

=COUNTIFS(A2:A14,">"&A11,A2:A14,"<"&A10)

If you wish to include the specified dates as well in the count, use ‘>=’ and ‘<=’ operators. Here, go with this formula:

=COUNTIFS(A2:A14,">=09-02-2020",A2:A14,"<=20-08-2021")

We used date directly in the criteria instead of cell reference for this example.

How to Handle COUNTIF and COUNTIFS with Multiple Criteria in Excel

COUNTIF function is mostly used for counting cells with single criteria(condition) in one range. But you can still use COUNTIF to count cells that match multiple conditions in the same range. However, the COUNTIFS function can be used to count cells that meet multiple conditions in the same or different ranges.

How to Count Numbers Within a Range

You can count cells containing numbers between the two specified numbers using two functions: COUNTIF and COUNTIFS.

COUNTIF to Count Numbers Between Two Numbers

One of the common uses for the COUNTIF function with multiple criteria is counting the numbers between two specified numbers, e.g. to count numbers greater than 10 but less than 50. To count numbers within a range, conjoin two or more COUNTIF functions together in one formula. Let us show you how.

Let’s say you want to count cells in the range B2:B9 where a value is greater than 10 and less than 21 (not including 10 and 21), go with this formula:

=COUNTIF(B2:B14,">10")-COUNTIF(B2:B14,">=21")

The difference between two numbers is found by subtracting one formula from another. The first formula counts the numbers greater than 10 (which is 7), the second formula returns the count of numbers greater than or equal to 21 (which is 4), and the result of the second formula is subtracted from the first formula (7-4) to get the count of numbers between two numbers (3).

If you want to count cells with a number is greater than 10 and less than 21 in the range B2:B14, including numbers 10 and 21, use this formula:

=COUNTIF(B2:B14,">=10")-COUNTIF(B2:B14,">21")

COUNTIFS to Count Numbers Between 2 Numbers

To count numbers between 10 and 21 (excluding 10 and 21) are contained in cells B2 through B9, use this formula:

=COUNTIFS(B2:B14,">10",B2:B14,"<21")

To include 10 and 21 in the count, just use ‘greater than or equal to’ (>=) instead of ‘greater than’ and ‘less than or equal to’ (<=) instead of ‘less than’ operators in the formulas.

COUNTIFS to Count Cells with Multiple Criteria (AND Criteria)

The COUNTIFS function is the plural counterpart of the COUNTIF function that counts cells based on two or more criteria in the same or multiple ranges. It is known as ‘AND logic’ because the function is made for counting cells only when all of the given conditions are TRUE.

For example, we want to find out how many times (count of cells) that bread (value in column A) has been sold less than 5 (value in column C).

We can use this formula:

=COUNTIFS(A2:A14,"Bread",C2:C14,"<5")

COUNTIF to Count Cells with Multiple Criteria (OR Criteria)

If you want to count the number of cells that meet multiple criteria in the same range, join two or more COUNTIF functions together. For example, if you want to find out how many times ‘Bread’ or ‘Cheese’ are repeated in the specified range (A2:A14), use the below formula:

=COUNTIF(A2:A14,"Bread")+COUNTIF(A2:A14,"Cheese")

This formula counts cells for which at least one of the conditions is TRUE. That’s why it’s called ‘OR logic’.

If you wish to evaluate more than one criteria in each of the functions, it’s better to use COUNTIFS instead of COUNTIF. In the example below, we want to get the count of “Ordered” and “Delivered” status for ‘Bread’, so we would use this formula:

=COUNTIFS(A2:A14,"Bread",C2:C14,"Ordered")+COUNTIFS(A2:A14,"Bread",C2:C14,"Delivered")

We hope this easy, but rather a long tutorial will give you some idea about how to use COUNTIF and COUNTIF functions in Excel.

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

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.

Like this post? Please share to your friends:
  • How to do corrections in word
  • How to do code in excel
  • How to do charts in word
  • How to do capital letter in excel
  • How to do calendar in word