Count if Formula in Excel: Step-by-Step Guide

Formulas & functions · Updated November 23, 2026

The COUNTIF formula in Excel counts cells that meet a single condition, and its syntax is =COUNTIF(range, criteria). For example, =COUNTIF(A2:A20, "Paid") returns the number of cells in A2:A20 that contain the text “Paid”.

What COUNTIF Does and When to Use It

COUNTIF is one of the most-used functions in Excel because it answers a simple question: “How many items in this list match this rule?” It works on numbers, text, dates, and wildcards, and it can count cells that are greater than, less than, equal to, or not equal to a value. You might use it to count how many sales exceeded $500, how many students passed a test, or how many times a product name appears in an inventory log.

The function takes exactly two arguments:

  • range – the group of cells you want to check (e.g., A2:A100).
  • criteria – the condition that determines which cells to count. This can be a number, text, expression, or cell reference.

If you need to count based on multiple conditions (e.g., “Paid” AND “Amount > 100”), use COUNTIFS instead. COUNTIFS works the same way but accepts multiple range/criteria pairs.

How to Write a COUNTIF Formula: Step by Step

Assume you have a list of orders in column A (A2:A20) and you want to count how many are marked “Shipped”.

  1. Click an empty cell where you want the result, say B2.
  2. Type =COUNTIF(.
  3. Select the range A2:A20 (or type it manually).
  4. Type a comma, then enter the criteria. For text, use double quotes: "Shipped".
  5. Close the parenthesis and press Enter: =COUNTIF(A2:A20, "Shipped").

If the cell contains the word “Shipped” exactly (case-insensitive), Excel counts it. The result appears immediately. For example, if 7 orders are marked “Shipped”, the formula returns 7.

Using Cell References, Numbers, and Dates in Criteria

Instead of typing the criteria directly, you can reference another cell. This makes the formula dynamic. For instance, if you put the value 100 in cell D1 and want to count how many numbers in B2:B20 are greater than that, write:

=COUNTIF(B2:B20, ">"&D1)

The ampersand (&) joins the comparison operator with the cell reference. For numbers, you can also write the number directly: =COUNTIF(B2:B20, ">100"). For dates, use a date serial number or a cell reference with a date, and enclose the operator in quotes: =COUNTIF(C2:C20, ">="&DATE(2025,1,1)).

Common comparison operators you can use inside criteria:

  • ">10" – greater than 10
  • "<0" – less than zero
  • "<>"&A1 – not equal to the value in A1
  • "=Yes" – equal to the text "Yes" (the equals sign is optional)

Counting Text with Wildcards: Partial Matches

To count cells that contain a specific word or pattern, use wildcards: the asterisk (*) for any sequence of characters and the question mark (?) for any single character. For example, to count all cells in A2:A20 that contain the word "apple" anywhere, use:

=COUNTIF(A2:A20, "*apple*")

To count cells that start with "A" and have exactly 5 characters, use "A????". Wildcards only work with text; they do not work with numbers. If you need to count cells that contain a literal asterisk or question mark, you must escape it with a tilde (~), like "~*".

Common Problems and How to Fix Them

One frequent issue is getting a zero when you expect a count. This often happens when the criteria text has extra spaces, or when the range contains numbers stored as text. Check for leading/trailing spaces with the TRIM function, or convert text numbers to real numbers using the VALUE function.

Another problem is counting cells with errors like #N/A. COUNTIF ignores error values, so if you need to count them, use =COUNTIF(range, "#N/A") which actually works because the criteria is the error text. However, this only works if the error is exactly #N/A.

If you need to count blank cells, use "" as the criteria: =COUNTIF(A2:A20, ""). To count non-blank cells, use "<>" (not equal to nothing). Note that "<>" counts cells that contain any character, including spaces, but not truly empty cells.

COUNTIF vs. COUNTIFS vs. SUMPRODUCT

COUNTIF handles one condition. COUNTIFS handles many conditions, and its syntax is =COUNTIFS(range1, criteria1, range2, criteria2, ...). For example, to count orders that are "Shipped" and have a value over $100, you would write:

=COUNTIFS(A2:A20, "Shipped", B2:B20, ">100")

SUMPRODUCT is a more flexible alternative that can handle array operations, such as counting with OR logic or counting across multiple columns. For instance, to count cells in A2:A20 that are either "Red" or "Blue", you could use =SUMPRODUCT(--((A2:A20="Red")+(A2:A20="Blue")>0)). However, COUNTIFS is simpler and faster for most standard multi-condition counts.

Performance Tips for Large Data Sets

COUNTIF is fast, but if you use it on thousands of rows, it can slow down your workbook, especially if you copy it down many cells. To improve performance, avoid using full-column references like A:A unless necessary; instead, limit the range to your actual data (e.g., A2:A1000). If you need to count based on a condition that changes often, consider using a PivotTable or the newer dynamic array functions like FILTER combined with COUNTA, which can be more efficient in Microsoft 365.

Frequently Asked Questions

How do I count cells that contain specific text but not as part of another word? Use wildcards with word boundaries: =COUNTIF(A2:A20, "* apple *") will count cells that have "apple" surrounded by spaces. This is not perfect, but it works for most cases. For exact word matching, you might need to use SUMPRODUCT with ISNUMBER and SEARCH.

Can COUNTIF be case-sensitive? No, COUNTIF is not case-sensitive. It treats "APPLE" and "apple" the same. If you need case-sensitive counting, use SUMPRODUCT with EXACT: =SUMPRODUCT(--EXACT(A2:A20, "Apple")).

Why does COUNTIF return 0 when the criteria is a number greater than 100? This often happens if the numbers in the range are stored as text. Select the range, look for a green triangle warning, and convert to number using the error check or by multiplying by 1. Alternatively, use =COUNTIF(A2:A20, ">"&100) and ensure the range has numeric values.

How can I count cells that are not equal to a specific value? Use =COUNTIF(range, "<>"&value). For example, =COUNTIF(A2:A20, "<>Paid") counts all cells that are not exactly "Paid", including blanks. To exclude blanks, use =COUNTIFS(A2:A20, "<>Paid", A2:A20, "<>").

Does COUNTIF work with dates? Yes, but you need to be careful with how Excel stores dates. Use a cell reference with a date, or use the DATE function: =COUNTIF(C2:C20, ">="&DATE(2025,1,1)). If you type a date directly in quotes, it may be interpreted as text, so always use DATE or a cell reference.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.