Excel COUNTIF Function: Syntax, Wildcards and 8 Examples
The Excel COUNTIF function counts the cells in a range that meet one condition. Use it to count how many orders are marked Paid, how many scores are above 50, or how many cells are not blank, without filtering or counting by hand.
COUNTIF syntax
The formula is =COUNTIF(range, criteria). The range is the group of cells to look at, such as B2:B100. The criteria is the condition: a number, a piece of text, a cell reference, or a comparison written in quotation marks such as ">50".
For example, if column B holds order status, =COUNTIF(B2:B100,"Paid") returns how many rows say Paid. Text matching ignores upper and lower case, so "paid" and "PAID" are counted too.
COUNTIF examples you will use most
| Goal | Formula | What it counts |
|---|---|---|
| Equal to a number | =COUNTIF(B2:B100,50) | Cells equal to 50 |
| Greater than | =COUNTIF(B2:B100,">50") | Cells above 50 |
| Not equal to text | =COUNTIF(A2:A100,"<>Cancelled") | Cells that are not Cancelled |
| Not blank | =COUNTIF(A2:A100,"<>") | Cells that contain anything |
| Blank cells | =COUNTIF(A2:A100,"") | Empty cells |
| Contains text | =COUNTIF(A2:A100,"*late*") | Cells with the word late anywhere |
| Starts with | =COUNTIF(A2:A100,"INV*") | Cells that begin with INV |
| Cell reference | =COUNTIF(B2:B100,">"&D1) | Cells above the value in D1 |
Notice the last row. When the condition uses a comparison and a cell, join them with the ampersand: ">"&D1. Writing ">D1" inside the quotation marks would look for the literal text D1 and return zero.
Wildcards: the star and the question mark
Two wildcard characters work inside text criteria. The star (*) stands for any number of characters, and the question mark (?) stands for exactly one. "A*" matches Ahmed and Anna. "??-??" matches codes such as 12-34. To count a real star or question mark, put a tilde before it, for example "~*".
COUNTIF between two numbers
COUNTIF takes one condition, so a range needs two COUNTIFs: =COUNTIF(B2:B100,">=50")-COUNTIF(B2:B100,">80") counts values from 50 up to and including 80. Another option is COUNTIFS, which accepts several conditions at once: =COUNTIFS(B2:B100,">=50",B2:B100,"<=80").
COUNTIF with multiple criteria: OR logic
COUNTIF alone cannot say "Paid or Pending". Add two COUNTIFs together: =COUNTIF(A2:A100,"Paid")+COUNTIF(A2:A100,"Pending"). If one cell can match both conditions, it would be counted twice, so check that the conditions do not overlap. For AND logic across different columns, use COUNTIFS.
Count dates with COUNTIF
Dates are numbers, so comparisons work. To count dates in the past use =COUNTIF(C2:C100,"<"&TODAY()). To count dates in a given month, use COUNTIFS with a start and an end date: =COUNTIFS(C2:C100,">="&DATE(2026,12,1),C2:C100,"<"&DATE(2027,1,1)).
Count duplicates and unique entries
To see how many times each name appears, put =COUNTIF($A$2:$A$100,A2) next to the list and fill down. Any value above 1 is a duplicate. Highlight them with conditional formatting, or remove them with the steps in our guide on how to remove duplicates in Excel. The dollar signs lock the range so it does not move when you copy the formula.
Why your COUNTIF is not working
| Problem | Likely cause | Fix |
|---|---|---|
| Returns 0 but you can see matches | Numbers stored as text, or extra spaces | Convert to numbers, use TRIM to clean text |
| Wrong count with long numbers | COUNTIF reads only 15 digits and text over 255 characters fails | Add a helper column or use SUMPRODUCT |
| Comparison counts nothing | Operator not inside quotation marks | Write ">50" not >50 |
| Result changes when copied | Range not locked | Use $A$2:$A$100 |
| #VALUE! with another sheet | Closed workbook referenced | Open the source workbook |
When a result looks wrong, test the criteria on a small sample of five or six rows where you know the answer. If the small test works, the problem is in the data, usually hidden spaces or text-formatted numbers.
Where to go next
COUNTIF counts; its sibling adds. Read the SUMIF guide to total values that meet a condition, and the IF function guide to return different results from a test. If you are still learning the basics, start with Excel formulas for beginners.
Frequently asked questions
What is the difference between COUNTIF and COUNTIFS? COUNTIF tests one condition on one range. COUNTIFS tests several conditions, across the same or different ranges, and counts rows where all of them are true.
Is COUNTIF case sensitive? No. For a case-sensitive count use SUMPRODUCT with EXACT.
Can COUNTIF count colored cells? No. It reads values, not formatting. Use a filter by color with SUBTOTAL, or add a status column.
Does COUNTIF work in Google Sheets? Yes, with the same syntax and wildcards.
How do I count cells that are not blank? Use =COUNTIF(range,"<>"), or COUNTA when you do not need a condition.
Summary
Write the range, then the criteria in quotation marks. Join comparisons to cell references with the ampersand, use star and question mark for partial matches, add COUNTIFs for OR logic, and switch to COUNTIFS when several conditions must all be true. Check for hidden spaces and numbers stored as text when the count looks wrong.
COUNTIF gets easier with practice on your own data. If you prefer guided video lessons, this Udemy Excel course covers formulas from beginner to advanced (affiliate link: we earn a commission if you buy through it, at no extra cost to you). The examples above are enough to learn COUNTIF without it.
Related guides: Excel IF Function: Multiple Conditions, Nested IF and Fixes When It Fails, How to Remove Duplicates in Excel: 4 Safe Methods and Fixes When It Finds None, Excel SUMIF Function: Syntax, 5 Examples and Fixes for Wrong Totals.
Comments
Post a Comment