Skip to main content

COUNTIF() Excel: Count Cells Based on Conditions

Use Excel’s COUNTIF() function to quickly count cells matching specific criteria like text, numbers, dates, and wildcard characters.
Updated Mar 13, 2025  · 8 min read

In this article, I will walk you through using Excel's COUNTIF() function to count how often something appears in a list. It’s perfect when you have to find numbers greater than a certain value or filter data based on a condition. As you will see, we can use it with text, numbers, dates, and even wildcards when you’re unsure of the exact match.

The Quick Answer

To use the COUNTIF() function in Excel: 

  • Type =COUNTIF( in a cell

  • Select the range from which you want to count the values.

  • Type ,

  • Then, apply the condition.

  • Close the parenthesis )

  • Hit Enter.

For example, to count if greater than 0 values appear in the range A2:A10, we will write

=COUNTIF(A2:A10, ">0")

Using COUNTIF() function in Excel to count the number greater than 0.

Using COUNTIF() to count the numbers greater than 0. Image by Author.

Understanding COUNTIF() Function 

Let me now elaborate a bit on the syntax: The COUNTIF() function in Excel is a statistical function that counts the number of cells within a specified range, meeting a given condition. It is widely used for data analysis, filtering, and reporting.

Excel COUNTIF() syntax

=COUNTIF(range, criteria)

Here:

  • range are the cells that will be checked for the condition.

  • criteria is 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

Let's practice using these two conditions with a basic example.

If I want to count how many numbers in B2:B10 are less than 100, I type the following:

=COUNTIF(B2:B10, "<100")

Since I’m using <, I added quotation marks. Otherwise, Excel won’t understand my condition.

using COUNTIF to count numbers that are less than 100 in Excel.

Count the numbers that are less than 100 using COUNTIF(). Image by Author.

Advance Your Career with Excel

Gain the skills to maximize Excel—no experience required.

Start Today for Free

All the Different Ways To Use Excel 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:

=COUNTIF(A2:A10, "Apple")

This formula will count all the cells in that range that exactly match Apple.

Counting cells with text using COUNTIF() in Excel.

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. For example, I have a dataset and now I can find different things from this with the COUNTIF() formula.  

  • 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 500 in 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 in Excel.

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. There are two types of wildcards:  

  • * matches any number of characters.
  • ? matches only a single character. 

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:

=COUNTIF(A2:A10, "*n*")

This formula uses the asterisk wildcard character *, which represents any number of characters (including zero). By typing "*n*", Excel searches for cells where "n" appears anywhere in the text — at the beginning, middle, or end. The formula counts all matching cells in the range A2:A10 and returns the total count of fruits containing the letter "n".

To count all four-letter fruits that start with K, I type:

=COUNTIF(A2:A10,"K???")

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 and display the final result. 

Using wildcard technique in COUNTIF() function in Excel.

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:

=COUNTIF(B2:B11, D2)

Or we can even write the logical operator in the quotation marks inside the formula and use & to reference the cell D3 like this:

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

Count cells using cell reference in COUNTIF() function in Excel.

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:

=COUNTIF(B2:B11,"")

And to count how many fruits are available (non-empty cells), I use this formula:

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

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 COUNIF() function in Excel.

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:

=COUNTIF(B2:B9, B11)

And to check who was hired on or before the date in cell B11, I use this formula:

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

Count difference in dates using COUNTIF() function in Excel.

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:

=COUNTIF(B2:B9, ">="&B12) - COUNTIF(B2:B9, ">"&B13)

Alternatively, you can use the COUNTIFS() function for multiple criteria like this:

=COUNTIFS(B2:B9,">="&B12,B2:B9,"<="&B13)

Both will give the same result. 

Use COUNTIF() for two conditions in Excel.

Use COUNTIF() for two conditions. Image by Author.

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.

Despite COUNTIFS() being newer and more capable with AND conditions, COUNTIF() still has its place in Excel. It often creates more readable formulas for simple conditions, making your spreadsheets easier to understand and maintain. More importantly, unlike COUNTIFS(), COUNTIF() handles OR conditions, where you want to count cells that meet any one of several criteria.

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 function in Excel.

Applying OR logic using COUNTIF(). Image by Author. 

Suppose, I also have to know how many times a value has 300 and kiwi in the same row. For this, I can use COUNTIFS():

=COUNTIFS(B1:B11, "300", A1:A11, "kiwi")

The formula will count the rows where both conditions are met. However, it gives 0 because neither of the conditions was met. 

Applying AND logic using COUNTIFS function in Excel.

Applying AND logic using COUNTIFS(). Image by Author. 

This distinction is helpful to know, which is why we included in our Excel formulas cheat sheet. And if you really want to stay current with the latest developments, I recommend taking our Excel Fundamentals skill track.

Common Errors and Troubleshooting

Even the best Excel users sometimes run into COUNTIF() problems. The function is helpful but has a few quirks that can trip you up. Here are the most common issues people face and how to solve them quickly.

Incorrect count for long text strings

COUNTIF() doesn't support text strings longer than 255 characters. If you work with longer chunks of text and get unexpected results, try using CONCATENATE() or the & operator to break down and combine your criteria into manageable form: 

=COUNTIF(range, CONCATENATE("First part of text", "Second part of text"))

Or

=COUNTIF(range, "First part of text" & "Second part of text")

VALUE! error in COUNTIF()

A #VALUE! error in COUNTIF() often happens when the formula references a closed workbook. This happens because Excel does not allow COUNTIF() to count data from an external file unless the file is open. To solve this, make sure the referenced workbook is open before running the formula. The error should disappear once the file is open, and COUNTIF() will work properly.

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 you won’t get the output.

 or example, the formula below will show an error:

=COUNTIF(B2:B10,>500)

To avoid this, make sure the logical operator is enclosed in the quotation marks. 

=COUNTIF(B2:B10,">500")

Excel COUNTIF() Best Practices

Here are some key practices to follow when you work with COUNTIF() in Excel. 

  • Use named ranges: Instead of selecting a range like A2:A10 in your formula, give a customized name to the range to make the formula easier to understand. For example, to count how many times Banana appeared in a list, we’d use =COUNTIF(A2:A10, "Banana"). But if I name the range to Items and use the cell reference for the condition, I can update the formula like this: =COUNTIF(Items, C2). This way the formula is more clear and easier to understand. 

  • Use COUNTIFS() for multiple conditions: Sometimes, we have to count data based on more than one condition. In such a case, instead of using multiple COUNTIF() formulas, use COUNTIFS() because it is the best choice for applying multiple filters.

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

Just like many other Excel functions, COUNTIF() is also one of the most helpful ways to count and filter data. Instead of manually going through your list, you can use this function to find what you need instantly. And the best part is that it works with text, numbers, blank cells, and patterns, which makes data analysis easier. 

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. 


Laiba Siddiqui's photo
Author
Laiba Siddiqui
LinkedIn
Twitter

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?

You can count duplicates of a value in a specific range with the COUNTIF() function. 

For example =COUNTIF(A2:A10, A2) will show you the count of duplicate values in the specified range. If you want to learn how to find unique values too, check out our article on How to Count Unique Values in Excel.

Can I use COUNTIF() to count dates based on today’s date?

Yes, you can but make sure to combine COUNTIF()  with the TODAY() function.

For example, to count tasks:

  • due in a week: =COUNTIF(A2:A10,"="&TODAY()+7)

  • overdue: =COUNTIF(A2:A10, "<"&TODAY())

Can I use COUNTIF() for non-adjacent cells?

COUNTIF() only works with continuous ranges which means you can’t select random cells here and there. But we can use multiple COUNTIF() functions and add them up like this:

=COUNTIF(A2, ">10") + COUNTIF(A3, ">10") + COUNTIF(A4, ">10")

This checks each cell individually and adds up the counts.

How do I use COUNTIF() with case sensitivity?

COUNTIF() is not case-sensitive. To count with case sensitivity, use the SUMPRODUCT() function combined with the EXACT() function:

=SUMPRODUCT(--EXACT(A2:A10, "Apple"))

This will count only exact case-sensitive matches of Apple.

Topics

Learn Excel with DataCamp

track

Excel Fundamentals

16hrs hr
Gain the essential skills you need to use Excel, from preparing data to writing formulas and creating visualizations. No prior experience is required.
See DetailsRight Arrow
Start Course
See MoreRight Arrow
Related

tutorial

SUMIFS() Function in Excel: Sum Data with Multiple Criteria

The SUMIFS() function in Excel sums values that meet multiple criteria, making it useful for conditional calculations with numbers, dates, and text. Learn to use SUMIFS() with syntax, examples, and best practices.
Laiba Siddiqui's photo

Laiba Siddiqui

8 min

tutorial

COUNT() SQL FUNCTION

COUNT() lets you count the number of rows that match certain conditions. Learn how to use it in this tutorial.
Travis Tang 's photo

Travis Tang

3 min

tutorial

Nested IF() in Excel: A Quick Solution for Many Conditions

Discover how to handle complex criteria in a single formula. Elevate your reporting in a way that saves time and effort and reduces mistakes.
Laiba Siddiqui's photo

Laiba Siddiqui

10 min

tutorial

Conditional Formatting in Excel: A Beginner’s Guide

Explore conditional formatting in Excel with simple to advanced examples and their best practices.
Joleen Bothma's photo

Joleen Bothma

7 min

tutorial

How to Count Unique Values in Excel: What You Need to Know

Learn to count unique values in Excel using basic and advanced formulas. See the difference between unique and distinct values.
Laiba Siddiqui's photo

Laiba Siddiqui

8 min

tutorial

How to Highlight Duplicates in Excel

Explore how you can identify duplicate entries in Excel using Conditional Formatting, the COUNTIF() formula, and Power Query. Learn best practices and troubleshoot issues.
Laiba Siddiqui's photo

Laiba Siddiqui

6 min

See MoreSee More