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)
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. |
|
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.
See also
COUNTIFS function
IF function
COUNTA function
Overview of formulas in Excel
IFS function
SUMIF function
Need more help?
Want more options?
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
COUNTIF function in Excel is used to count the number of cells in the range in question, the data contained in which meet the criterion passed as the second argument to this function, and returns the corresponding numeric value.
COUNTIFS function can be used to analyze numeric values, text strings, dates, and other types of data. It can be used to determine the number of non-repeating values in a range of cells, as well as the number of cells with data that only partially coincide with the specified criterion. For example, an Excel table contains a column with the full name of customers. To determine the number of namesake customers with the name Jon, you can enter the function =COUNTIF(A1:A300,»*Jon*»). The symbol «*» indicates any number of any characters before and after the substring «Jon».
Examples of using the COUNTIF function in Excel
Example 1. The Excel spreadsheet contains data on sales of goods in the hardware store for the day. Determine how much of the Samsung products are sold.
View source data table:
For the calculation we use the formula:
=COUNTIF(C3:C17,»Samsung») / A17
Argument Description:
- C3:C17 is the range of cells containing the names of the companies of the equipment sold;
- «Samsung» — search criteria (exact match);
- A17 is the cell storing the number of the last sale corresponding to the total number of sales.
The result of the calculation:
The percentage of Samsung products sold is a percentage of 40%.
Counting the number of a particular cell value in Excel provided
Example 2. According to the results of the exams, it is necessary to create a table containing data on the number of students who passed the subject for 5, 4, 3 points, respectively, as well as those who did not pass the subject.
View source table:
First select the cells E2:E5, enter the formula below:
=COUNTIF(B3:B19,D2:D5)
Argument Description:
- B3:B19 — cell range with exam grades;
- D2:D5 is the range of cells containing the criteria for counting the number of matches.
As a result, we get the table:
Statistical analysis of attendance using the account function in Excel
Example 3. The Excel spreadsheet stores data on page views of the site by the day. Determine the number of users of the site per day, as well as how many times a day users came to the site with default and user_1 logins.
View source table:
Since each user has his own unique identifier in the database (Id), let’s calculate the number of site users per day using the following array formula and to calculate it, press the key combination Ctrl + Shift + Enter:
The expression 1 / COUNTIF(A3:A20,A3:A20) returns an array of fractional numbers 1 / number_notes, for example, for a user with the nickname sam, this value is 0.25 (4 occurrences). The total sum of such values, calculated by the SUM function, corresponds to the number of unique occurrences, that is, the number of users on the site. The resulting value:
To determine the number of pages viewed by the users default and user_1, we write the formula:
As a result of the calculation we get:
Features of using the COUNTIF function in Excel
The function has the following syntax entry:
=COUNTIF(Range,Criteria)
Argument Description:
- Range — a required argument that accepts a link to one or several cells in which the number of matches with the specified criterion is required to be determined.
- Criteria — the condition according to which the calculation of the number of matches in the considered range is performed. The condition can be a boolean expression, a numeric value, a text string, a Date value, a cell reference.
Notes:
- When counting the number of occurrences in a range in accordance with two different conditions, a range of cells can be considered as a set containing two or more disjoint subsets. For example, in the table «Furniture» you need to find the number of tables and chairs. For calculations, we use the expression =COUNTIF(B3:B200,»*table*»)+COUNTIF(B3:B200,»*chair*»).
- If a text string is specified as a criterion, it should be noted that the case of characters does not matter. For example, the =COUNTIF(A1:A2,»Joni») function returns the value 2 if the cells «joni» and «Joni» are written in cells A1 and A2, respectively.
- If the criterion is passed as an argument to a reference to an empty cell or an empty string «», the result of the calculation for any range of cells will be the numeric value 0 (zero).
- The function can be used as an array formula if you need to calculate the number of cells with data that satisfies several criteria at once. This feature will be considered in one of the examples.
- The function in question can be used to determine the number of matches, either one at a time or according to several search criteria at once. In the latter case, two or more COUNTIF functions are used, the returned results of which are added or subtracted. For example, cells A1:A10 store a sequence of values from 1 to 10. To counting cells with numbers greater than 3 and less than 8, you must perform the following steps:
Download examples COUNTIF function for counting of cell in Excel
- write down the first function of COUNTIF with criterion «>3»;
- write the second function with the criterion «>=8»;
- to determine the difference between the returned values =COUNTIF(A1:10,»>3″)-COUNTIF(A1:A10,»>= 8″). That is, subtract from the set (3,+∞) the subset [8,+∞).
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")
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").
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")
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.
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:
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.
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)
Let’s still find the purchased furniture that isn’t equal to 5.
=COUNTIF(B1:B20,"<>5")
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")
As a result, people bought 2 tables. You can replace the word with a cell reference
=COUNTIF(A2:A21,E2)
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")
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?")
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*")
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")
Change the logical operator to count the amount of furniture that people bought less than 3 times:
=COUNTIF(B1:B20,"<3")
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")
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)
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
).
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.
-
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
COUNTIF function in excel is used to count the number of cells that match a single condition applied. It can include Dates, Numbers, and Texts. It uses various logical operators like <(Less Than), >(Greater Than), >=(Greater Than or Equal to), <=(Less Than or Equal to), =(Equals to), and <>(NOT) for matching the condition. It also uses some wildcard like * and ? for partial matching.
COUNTIF function in excel is used to count the number of cells.
Syntax: COUNTIF ( range, criteria) Arguments: 1. range:- Here ranges refers to the range of cells for which you want the cell count for a specific condition. 2. criteria:- Here criteria refers to the condition for which you want the cell count. Return Value: COUNTIF function in excel returns an integer value of the number of cells which satisfy the given condition.
Example 1:
Consider the student’s marks which are given below for and XYZ examination.
Understanding the arguments of the COUNTIF function in Excel
Understanding the argument of the COUNTIF function in Excel
Output:
Note: RED color cells are used for the reference that which cells would satisfy the given criteria. RED color doesn’t come in the output of COUNTIF.
The output of the marks of the students having greater than 80
Example 2:
Input |
Output |
Examples 3:
Some of the other examples are as follows for the COUNTIF function in excel.
We can find out that how many blank cells are there in the given range and also we can find out which are not blank cells in the given range.
- For finding number of Blank cells: = COUNTIF ( D1:D10, “” )
- For finding a number of not Blank cells: = COUNTIF ( D1:D10, “<>”)
We can use the COUNTIF criteria using the value from another cell using concatenation. In the below example it COUNTIF function will return the value which is equal to the cell E5. Here & is used for the concatenation.
= COUNTIF ( D1:D10, "=" & E5)
We can use the COUNTIF function with the DATE function also for finding the dates less than or more than the given DATE. The below example shows how to use the COUNTIF function with the DATE function. It will return some dates that are greater than 1-Jan-2021.
= COUNTIF ( D1:D10, ">" & DATE( 2021, 1, 1) )
Some Points to be remembered:
- COUNTIF is not case sensitive.
- COUNTIF will only check one condition at a time.
- COUNTIF needs a range for the evaluation.
- In COUNTIF the criteria must be enclosed in the double-quotes.
- If the criteria are evaluated from a different cell then that cell must not be enclosed in the double-quotes. E.g. “=” & E5
- It gives an error if the matching string exceeds 255 characters.