Home › Excel functions › COUNTIF
COUNTIF Formula in Excel: How to Use It, with Examples
The COUNTIF formula counts how many cells in a range meet a condition. How many orders are shipped, how many scores are above 80, how often a name appears: COUNTIF answers all of these in one formula.
In this guide
COUNTIF syntax
=COUNTIF(range, criteria)| Argument | What it means |
|---|---|
| range | The cells to check. |
| criteria | The condition a cell must meet to be counted, such as "Shipped", ">100" or a cell reference. |
Basic example: count orders by status
| A | B | C | |
|---|---|---|---|
| 1 | Order | Status | Amount |
| 2 | #1001 | Shipped | $120 |
| 3 | #1002 | Pending | $80 |
| 4 | #1003 | Shipped | $45 |
| 5 | #1004 | Cancelled | $200 |
| 6 | #1005 | Shipped | $60 |
| 7 | #1006 | Pending | $95 |
Three cells in B2:B7 say "Shipped", so the result is 3. COUNTIF isn't case-sensitive: "shipped" would give the same answer.
COUNTIF practice: try it yourself
Reading is one thing, typing it is another. Build the formula below step by step: the tips tell you what to type next, and you can click or drag across cells to add them, just like in Excel.
Task: Count how many invoices are "Paid", in D2: =COUNTIF(B2:B7,"Paid")
Types of criteria
| You want to count | Formula | Result |
|---|---|---|
| Exact text | =COUNTIF(B2:B7, "Pending") | 2 |
| Everything except | =COUNTIF(B2:B7, "<>Shipped") | 3 |
| Numbers above 100 | =COUNTIF(C2:C7, ">100") | 2 |
| Text ending in "ed" | =COUNTIF(B2:B7, "*ed") | 4 |
| Non-empty cells | =COUNTIF(B2:B7, "<>") | 6 |
| Empty cells | =COUNTIF(B2:B7, "") | 0 |
Operators go between quotes. The wildcard * matches any number of characters, ? matches one. In the fourth example, "Shipped" (×3) and "Cancelled" both end in "ed".
Use a cell as the condition
With a status typed in E2, this counts that status:
Comparison operators: what to type
| Type | Means |
|---|---|
| = | is equal to |
| > | greater than |
| < | less than |
| >= | greater than or equal to: first >, then = |
| <= | less than or equal to: first <, then = |
| <> | not equal to: first <, then > |
Always two separate keys, never a special symbol. In criteria, put the operator and the value together inside quotes, such as ">=500" or "<>Paid" as the condition.
To combine an operator with a cell value, join them with &. With 100 in E3:
Find duplicates with COUNTIF
COUNTIF can tell you how often a value appears in a list. Put this next to each row and copy it down:
=COUNTIF($A$2:$A$100, A2)>1It returns TRUE for every value that appears more than once. You can use the same formula as a conditional formatting rule (Home › Conditional Formatting › New Rule › Use a formula) to highlight duplicates automatically.
COUNTIF with dates
Dates are numbers in Excel, so you count them with the same operators. Put the operator between quotes and join it to a date function with &:
=COUNTIF(C2:C100, ">="&DATE(2026, 1, 1))counts dates from 1 January 2026.=COUNTIF(C2:C100, "<"&TODAY())counts dates in the past, for example overdue invoices.=COUNTIFS(C2:C100, ">="&E1, C2:C100, "<="&F1)counts dates between the dates in E1 and F1.
Avoid typing a date inside the quotes: whether Excel reads it correctly depends on the date settings of the computer.
COUNTIF not equal to
Use <> for "not equal to". =COUNTIF(B2:B100, "<>"&E1) counts every cell that is not equal to the value in E1. Note that empty cells count as well, because they are not equal to E1 either. To skip them, add a second condition: =COUNTIFS(B2:B100, "<>"&E1, B2:B100, "<>").
COUNTIFS: multiple conditions
To count rows that meet several conditions, use COUNTIFS with pairs of range and criteria:
=COUNTIFS(B2:B7, "Shipped", C2:C7, ">100")Only order #1001 is both shipped and above $100, so the result is 1. All conditions must be true for a row to be counted.
Common COUNTIF mistakes
- The count is 0. Check for extra spaces in the data and the exact spelling of the criteria.
- Numbers aren't counted. Numbers stored as text don't match a numeric condition like
">100". - An operator with a cell doesn't work. Write
">"&E3, not">E3". - #VALUE! with long text. COUNTIF can't match strings longer than 255 characters.
- #VALUE! with another workbook. If the range is in a different workbook, COUNTIF only works while that workbook is open. Open it, or use
=SUMPRODUCT(--([Sales.xlsx]Sheet1!B2:B100="Shipped")), which also works when it's closed. - You need case-sensitive counting. COUNTIF can't do that. Use
=SUMPRODUCT(--EXACT(B2:B7, "Shipped"))instead.
COUNTIF and related functions
Not sure which counting function you need? This overview shows the differences:
| Function | What it counts | Example |
|---|---|---|
| COUNT | Cells with a number | =COUNT(B2:B100) |
| COUNTA | All cells that aren't empty | =COUNTA(A2:A100) |
| COUNTBLANK | Empty cells | =COUNTBLANK(A2:A100) |
| COUNTIF | Cells that meet one condition | =COUNTIF(B2:B100, "Shipped") |
| COUNTIFS | Rows that meet several conditions | =COUNTIFS(B2:B100, "Shipped", C2:C100, ">100") |
| SUMIF | Adds up values instead of counting them | =SUMIF(B2:B100, "Shipped", C2:C100) |
More COUNTIF examples
Copy a formula and change the ranges to match your own data.
| What you want | Formula |
|---|---|
| Count cells that are not empty | =COUNTIF(A2:A100, "<>") |
| Count empty cells | =COUNTIF(A2:A100, "") |
| Count values greater than the number in E1 | =COUNTIF(B2:B100, ">"&E1) |
| Count numbers between 10 and 20 | =COUNTIFS(B2:B100, ">=10", B2:B100, "<=20") |
| Count cells that contain the text in E1 | =COUNTIF(A2:A100, "*"&E1&"*") |
| Count dates on or after 1 January 2026 | =COUNTIF(C2:C100, ">="&DATE(2026, 1, 1)) |
Keep learning
Frequently asked questions
What's the difference between COUNT, COUNTA and COUNTIF?
COUNT counts cells with numbers, COUNTA counts all non-empty cells, and COUNTIF counts only the cells that meet a condition you set.
How do I count cells with an OR condition?
Add two COUNTIFs: =COUNTIF(B2:B7, "Shipped") + COUNTIF(B2:B7, "Pending") counts both statuses.
How do I count cells that contain a word?
Wrap the word in wildcards: =COUNTIF(A2:A100, "*invoice*") counts every cell that contains "invoice" anywhere.
Is COUNTIF case-sensitive?
No. To count with exact case, use SUMPRODUCT with EXACT.
How do I count cells that are not blank?
Use =COUNTIF(A2:A100, "<>") or the shorter =COUNTA(A2:A100). Both skip empty cells. Note that a formula that returns an empty text ("") still counts as filled.
How do I count values between two numbers?
Use COUNTIFS with two conditions on the same range: =COUNTIFS(B2:B100, ">=10", B2:B100, "<=20"). COUNTIF on its own takes only one condition.
Can COUNTIF count coloured cells?
No. COUNTIF looks at values, not at the fill colour. Filter by colour instead (Data > Filter > Filter by Color) and count the visible cells with =SUBTOTAL(103, A2:A100), or count the condition that gave the cells their colour.
Can COUNTIF count in two separate ranges?
Not in one go: the range has to be one block. Add two COUNTIFs together: =COUNTIF(A2:A10, "Yes") + COUNTIF(D2:D10, "Yes").