Different Ways to Use COUNTIF() in Excel
Now that you know how the COUNTIF() function works in Excel, let's look at some more examples of where we can use it.

Counting cells that contain text
COUNTIF() can count how many times a specific text appears in data. For example, I have a list of fruits in A2:A10 and want to know how many times Apples appear. For this, I enter:
This formula will count all the cells in that range that exactly match Apple.

Count cells with text using COUNTIF(). Image by Author.
Counting numeric values
We can also count numbers greater than, less than, or equal to a specific value. With the fruit quantities in B2:B10, I can count:
-
To count how many fruits have a quantity greater than
500:=COUNTIF(B2:B10,">500") -
To count how many fruits’ quantities are not equal to
500:=COUNTIF(B2:B10, "<>500") -
To find how many fruits are exactly
500in quantity:=COUNTIF(B2:B10, "500") -
To count how many fruits have quantity below
500:=COUNTIF(B2:B10,"<500")

Count numeric values using the COUNTIF() function. Image by Author.
Using wildcards for partial matches
Sometimes we want to count cells that contain a specific part of a word or phrase. In that case, we use wildcards. Excel has two wildcards, plus an escape character:
*matches any number of characters, including none.?matches exactly one character.~(tilde) makes the next character literal, so"*~?"counts cells that end in a real question mark.
For example, I have a fruits dataset and I use two different formulas here to show you how COUNTIF() handles wildcard cases. To count all the fruits that contain n anywhere in the fruit’s list, I enter the following formula:
The asterisk stands for any number of characters, so "*n*" counts every cell in A2:A10 with an n anywhere in the text. COUNTIF() ignores case, so a name that starts with a capital N counts too.
To count all four-letter fruits that start with K, I type:
This formula uses the wildcard character ?, which represents exactly one character. By typing "K???", Excel counts all cells in the range A2:A10 that start with the letter K and have exactly four letters, such as Kiwi.

Use wildcards in the COUNTIF() function. Image by Author.
Applying criteria from another cell
Instead of hardcoding the conditions, we can even use the cell reference. This makes the formula more flexible because it updates automatically when the cell value changes.
If I want to know how many fruits have a quantity more than 300, I type the condition in the cell D2 and then use this cell reference in the formula like this:
Or we can even write the logical operator in the quotation marks inside the formula and use & to reference the cell D3 like this:

Count cells using cell reference in COUNTIF() function. Image by Author.
Counting blank and non-blank cells
Missing data can be just as important as the data you have. And COUNTIF() helps us spot those gaps. Let's say I’m managing inventory and want to know how many fruits are out of stock (blank cells). For this, I create the following formula:
And to count how many fruits are available (non-empty cells), I use this formula:
However, if your cell contains any invisible text like space or any special character, COUNTIF() will count them as non-blank cells.

Count blank and non-blank cells using COUNTIF() function. Image by Author.
Counting dates based on different conditions
We can also count dates based on different conditions. Let’s say we want to count how many employees were hired on the date in cell B11 (1 March 2024). So our formula would be:
And to count who was hired on or after the date in cell B11, I use this formula:

Count difference in dates using COUNTIF() function. Image by Author.
COUNTIF() with multiple criteria
We can also use COUNTIF() with multiple criteria. If I want to count how many dates fall between January 1, 2024, and January 30, 2024, I type:
Alternatively, you can use the COUNTIFS() function for multiple criteria like this:
Both will give the same result.

Use COUNTIF() for two conditions. Image by Author.
Counting how often each value appears
To build a frequency table, list each fruit once in column D and count it in column E with a locked range, so the formula can be copied down:
=COUNTIF($A$2:$A$11, D2)
In Excel for Microsoft 365 and Excel 2021 or later, one formula fills the whole column. Enter =UNIQUE(A2:A11) in D2 (see our UNIQUE() tutorial), then point COUNTIF() at its spill range in E2:
=COUNTIF(A2:A11, D2#)
The counts update when a new fruit appears in the list. Any count above 1 is a duplicate; to mark those in the sheet itself, see how to highlight duplicates in Excel.
Excel COUNTIF() vs COUNTIFS()
Excel's COUNTIF() function counts cells based on a single criterion, as we have seen in the examples, above, and we can even filter multiple conditions by using more than one COUNTIF(), as we saw in that last example.
Now is a good time to say that, if your data does require multiple criteria, Excel provides an extended and newer function called COUNTIFS(). While COUNTIFS() behaves exactly like COUNTIF() when only one condition is specified, it also lets you apply more than one condition.
With a single condition, COUNTIF() is the shorter and clearer formula. Neither function has an OR mode: every condition inside one COUNTIFS() must be true at once (AND logic). To count cells that meet any one of several criteria (OR logic), add COUNTIF() results together, as long as no cell can match two of the conditions.
Let’s understand this with a simple example:
=COUNTIF(B2:B11, "100") + COUNTIF(B2:B11, "900")
This formula will count cells where the value is either 100 or 900. Since no 900 is in the cells and only one 100 is present, it will show 1 as a result.

Applying OR logic using COUNTIF(). Image by Author.
With more values, an array constant keeps the formula short. COUNTIF() returns one count per value in the braces, and SUM() adds them up:
=SUM(COUNTIF(B2:B11, {100, 900}))
On the same data, this also returns 1.
r="ltr">Now suppose I want to count the rows where the quantity is 300 and the fruit is Kiwi. For this, I use COUNTIFS():
=COUNTIFS(B1:B11, "300", A1:A11, "kiwi")
The formula counts the rows where both conditions are true. It returns 0 here: Grapes is the only fruit with a quantity of 300, and Kiwi's quantity is 250, so no row meets both.

Applying AND logic using COUNTIFS(). Image by Author.
Our Excel formulas cheat sheet covers both functions, and the Excel Fundamentals skill track practices them in hands-on exercises.
Common Errors and Troubleshooting
Most COUNTIF() problems have one of five causes: long text, a closed source workbook, unquoted operators, stray spaces, or an array passed as the range. Here is how to fix each one.
Incorrect count for long text strings
COUNTIF() can't match criteria longer than 255 characters: it returns a wrong count or a #VALUE! error. Use SUMPRODUCT() instead, which compares the cells directly and has no length limit:
=SUMPRODUCT(--(A2:A10=D2))
Here, D2 holds the long text, and the double minus turns each TRUE or FALSE into 1 or 0 before SUMPRODUCT() adds them up.
#VALUE! error when the source workbook is closed
COUNTIF() returns #VALUE! when its range points to another workbook that is closed, because it can only read ranges from open files. Open the source workbook and the error clears. If the file has to stay closed, the SUMPRODUCT() pattern above works on closed workbooks.
Incorrect use of operators
Sometimes we may forget to enclose logical operators in quotation marks. Always make sure operators like >, <, and <> are inside quotes in your criteria. Otherwise, Excel won’t accept the formula.
For example, Excel rejects this formula with a “There’s a problem with this formula” message:
To avoid this, make sure the logical operator is enclosed in the quotation marks.
Count is lower than expected because of extra spaces
A cell that holds Apple with a trailing space doesn't match "Apple", so COUNTIF() skips it. Clean the column with TRIM(), or match around the spaces with a wildcard:
=COUNTIF(A2:A10, "*Apple*")
The wildcard version also counts Pineapple, so cleaning the data is the safer fix.
COUNTIF() won't accept an array as the range
The range argument has to be a real cell range, so Excel refuses a formula like =COUNTIF(YEAR(B2:B9), 2024) with “There’s a problem with this formula.” Do the calculation inside SUMPRODUCT() instead:
=SUMPRODUCT(--(YEAR(B2:B9)=2024))
On the hiring data from the dates example, this counts the employees who joined in 2024.
Excel COUNTIF() Best Practices
Here are some key practices to follow when you work with COUNTIF() in Excel.
-
Use named ranges and criteria cells: Name the range (for example,
ItemsforA2:A10) and type the condition in a cell, so=COUNTIF(A2:A10, "Banana")becomes=COUNTIF(Items, C2). The formula reads more clearly, and changingC2changes the count. -
Lock the range before copying: When you copy a
COUNTIF()formula down a column, write the range as an absolute reference, such as$A$2:$A$10, so it doesn't shift with each row. -
Use COUNTIFS() for multiple conditions: When every condition must be true, one
COUNTIFS()formula is shorter and easier to check than severalCOUNTIF()formulas combined.
COUNTIF() vs. Related Functions
Apart from COUNTIF() and COUNTIFS(), we have a lot of other Excel functions to count cells. However, each function has a specific purpose. So, let’s take a closer look at these:
| Function | What It Does | Example |
|---|---|---|
COUNTIF() | Counts the number of cells that match one condition. | Count how many times Apples appear in a list. |
COUNTIFS() | Counts cells that meet multiple conditions. | Count how many times Apples appear and the price is over $2. |
COUNT() | Counts numeric values only. | Count how many numbers are in a column, ignoring text. |
COUNTA() | Counts all non-empty cells. | Count all filled cells, including numbers, text, and symbols. |
COUNTBLANK() | Counts empty cells. | Count how many blank cells are in a column or range. |
Final Thoughts
COUNTIF() answers one question: how many cells in this range meet this condition? With quoted operators, wildcards and cell references, it handles the text, number, date and blank-cell counts that come up in everyday data analysis. When every condition has to be true at once, switch to COUNTIFS(); when the range is a calculated array or the text runs past 255 characters, switch to SUMPRODUCT().
If you want to learn more, start with our Introduction to Excel course to learn the essentials. For a strong foundation, the Excel Fundamentals skill track will take you through all the core concepts step by step. Finally, if you work with financial data, our Financial Modeling in Excel course will guide you on building professional financial models and forecasts.
I'm a content strategist who loves simplifying complex topics. I’ve helped companies like Splunk, Hackernoon, and Tiiny Host create engaging and informative content for their audiences.
Countif() FAQs
How do I count duplicates in a column?
Use COUNTIF() with the whole column as the range and one cell as the criteria. =COUNTIF($A$2:$A$10, A2) returns how many times the value in A2 appears; copy it down, and any result above 1 is a duplicate. To count distinct values instead, see how to count unique values in Excel.
Can I use COUNTIF() to count dates based on today’s date?
Yes. Join a comparison operator to TODAY() with &. =COUNTIF(A2:A10, "<"&TODAY()) counts overdue dates, and =COUNTIF(A2:A10, TODAY()+7) counts dates exactly one week from today. For a window, such as the next seven days, use =COUNTIFS(A2:A10, ">="&TODAY(), A2:A10, "<="&TODAY()+7), which checks both ends of the range.
Can I use COUNTIF() for non-adjacent cells?
Not in a single range argument. COUNTIF() needs one continuous range, so a selection like A2,A5,A9 won't work. Add separate COUNTIF() results instead, for example =COUNTIF(A2:A5, ">10") + COUNTIF(C2:C5, ">10"). Each part counts one block of cells, and the plus sign combines the totals.
How do I use COUNTIF() with case sensitivity?
COUNTIF() ignores case, so "apple" and "Apple" count as the same text. For a case-sensitive count, combine SUMPRODUCT() with EXACT(): =SUMPRODUCT(--EXACT(A2:A10, "Apple")). EXACT() returns TRUE only for exact-case matches, and the double minus turns those into 1s for SUMPRODUCT() to add.
What is the difference between COUNTIF() and COUNTIFS()?
COUNTIF() takes one range and one condition. COUNTIFS() takes up to 127 range and condition pairs and counts only the rows where every condition is true. With a single condition, both return the same result, so COUNTIFS() is the safer choice when a second condition might be added later.
Can COUNTIF() count cells by color?
No. COUNTIF() reads cell values, not formatting, so it can't count by fill or font color. A common workaround is to filter the column by color and count the visible cells with =SUBTOTAL(103, A2:A10). If the color comes from a conditional formatting rule, count with the same rule in COUNTIF() instead.





Excel's
COUNTIF()function counts the cells in a range that meet one condition: a word, a number, a comparison such as">500", a date, or a wildcard pattern. The syntax is=COUNTIF(range, criteria). In this tutorial, I go through each kind of condition with examples, show when to switch toCOUNTIFS(), and fix the errors people run into most often.If you are new to spreadsheets, the Understanding Excel course covers navigating a workbook and applying basic formulas, which is all you need to follow the COUNTIF examples below.
The Quick Answer
To use the
COUNTIF()function in Excel:Type
=COUNTIF(in a cellSelect the range from which you want to count the values.
Type
,Then, apply the condition.
Close the parenthesis
)Hit Enter.
For example, to count the values greater than
0in the rangeA2:A10, I write:Using COUNTIF() to count the numbers greater than 0. Image by Author.
Understanding the COUNTIF() Function
COUNTIF()is one of Excel's statistical functions: it checks every cell in a range against one condition and returns how many cells meet it. It works the same way in Excel for Microsoft 365, Excel 2024, Excel 2021 and earlier versions, and Google Sheets uses the same syntax.Excel COUNTIF() syntax
Here:
rangeare the cells that will be checked for the condition.criteriais the condition that determines which cells to count. This can be a number, text, logical operator, or even a wildcard pattern.Excel COUNTIF() basic example
Here is a basic example that uses both arguments.
If I want to count how many numbers in
B2:B10are less than100, I type the following:Since I’m using
<, I added quotation marks. Otherwise, Excel won’t understand my condition.Count the numbers that are less than 100 using COUNTIF(). Image by Author.