COUNTIF in Excel
The COUNTIF formula in Excel — also written as count if — counts cells that match one condition: a repeated order ID, a passing score, or status Shipped. The same COUNTIF works in Google Sheets (google spreadsheet count if). Use COUNTIFS for two or more conditions, count if not blank with "<>", and pair IF and COUNTIF when a count should drive a label.
COUNTIF Syntax & The 2 Arguments
COUNTIF walks range and counts the cells that meet criteria. It counts; it does not add. One condition, one number.
The cells to test (a status column B2:B6, or order IDs in A2:A11). COUNTIF checks every cell here.
The condition: quote text ("Shipped"), leave numbers bare (60), quote operators (">=60"), join a cell (">=" & E1), or use a wildcard ("*apple*" or "*").
COUNTIF example: shipped orders
Column B lists order status. This COUNTIF example counts only the Shipped rows — one range, one criterion.
| Order | Status |
|---|---|
| ORD-1 | Shipped |
| ORD-2 | Pending |
| ORD-3 | Shipped |
| ORD-4 | Cancelled |
| ORD-5 | Shipped |
COUNTIF checks B2:B6 for Shipped and returns 3. Switch to COUNTIFS when a second condition appears. For counting text cells instead of one word, use COUNTIF(A2:A6,"*") — the asterisk matches text and skips numbers and blanks.
COUNTIF vs COUNTIFS
COUNTIF takes one range/criteria pair. COUNTIFS stacks more pairs, and a row counts only when every pair matches. There is no sum range — do not copy the SUMIFS habit of putting a number column first.
| Region | Status |
|---|---|
| North | Shipped |
| South | Shipped |
| North | Pending |
| North | Shipped |
Two rows are both North and Shipped. COUNTIF(B2:B5, "Shipped") returns 3 because the South row counts too. Use COUNTIFS for the extra condition and leave single-condition counts on COUNTIF.
Counting text cells
COUNT counts numbers. COUNTA counts every non-blank. For counting text cells, the criterion is the wildcard "*". The asterisk matches text and skips numbers and truly blank cells.
| Cell | Value |
|---|---|
| A2 | apple |
| A3 | 12 |
| A4 | — |
| A5 | banana bread |
| A6 | 4 |
The result is 2: apple and banana bread. 12 and 4 are numbers, and A4 is blank, so none of them count. Use "?*" when the cell must contain at least one character, or "*bread*" to count cells that contain a word (1 in this range). Matching is not case-sensitive. A formula that returns "" is text to ISTEXT, but COUNTIF with "*" does not count it.
Excel COUNTIF: count if not blank
"<>" is the usual count if not blank criterion — it counts every non-empty cell (text and numbers). =COUNTIF(A2:A10, "<>""") is the same idea. Prefer COUNTA when you only need “anything filled”; keep COUNTIF when the not-blank test will later sit beside other COUNTIFS pairs.
IF and COUNTIF in Excel
When the answer should be a label, not a raw count, nest COUNTIF inside IF — the classic IF and COUNTIF pattern for duplicate flags:
COUNTIF returns how often the value appears; IF turns counts of 2 or more into Duplicate and everything else into Unique.
COUNTIF vs COUNT, COUNTA and COUNTBLANK
Excel counts cells five different ways and they are not interchangeable. Pick by what you are counting: numbers only, anything filled, empty cells, one condition, or several conditions.
| Function | Counts | Formula example |
|---|---|---|
COUNT | Cells holding numbers only | =COUNT(B2:B9) |
COUNTA | Non-blank cells, text or numbers | =COUNTA(A2:A9) |
COUNTBLANK | Empty cells | =COUNTBLANK(A2:A9) |
COUNTIF | Cells matching one condition | =COUNTIF(B2:B9, ">=60") |
COUNTIFS | Rows matching every condition | =COUNTIFS(A2:A9, "North", B2:B9, ">=60") |
The classic mistake is reaching for COUNT on a text column: it returns 0 because it only counts numbers. For "how many cells have something in them" use COUNTA; for "how many contain text" use COUNTIF(range, "*").
Two or more conditions: COUNTIFS, numeric ranges and OR logic
COUNTIFS takes range/criterion pairs and ANDs them: every pair has to match before a row is counted. Unlike SUMIFS there is no sum range — the first argument is already a range.
Rows in North with a score of 60 or more
Scores from 60 up to (not including) 80 — two criteria on the same range
North or South: add two COUNTIF results together
A criterion can also point at a cell, which is what makes a dashboard work: change the value in D1 and the count follows. Wrap the reference in wildcards when you need a partial match — "*"&D1&"*" counts cells containing whatever D1 holds.
Count duplicates and flag them
Lock the range with dollar signs before copying down: a helper column beside the data then tells you how many times each value appears.
In B2, copied down: how often the value in A2 appears in the column
Anything of 2 or more is a duplicate. Turning the same test into =COUNTIF($A$2:$A$11, A2)>1 and pasting it into a conditional-formatting rule highlights every repeated cell without adding a column at all.
Count unique values in one cell
4 COUNTIF Gotchas
1. Criteria quotes
Text criteria must be quoted: "Shipped". Numbers are bare: 60. A comparison is one string: ">=60". Writing >=60 bare is a syntax error. When the threshold lives in a cell, join it: ">=" & E1.
2. Writing COUNTIFS like SUMIFS
SUMIFS starts with a sum range. COUNTIFS does not — the first argument is the first criteria range. An extra number column shifts the pairs and returns 0 or #VALUE!.
3. Wildcards and case
COUNTIF ignores case (shipped = Shipped). "North*" also matches Northeast. Leave the asterisk off when you need an exact value.
4. Why the result is 0
Hidden spaces around the criterion (TRIM), numbers stored as text, or "*" pointed at a column of numbers. COUNTIF does not throw when nothing matches — it returns 0.
COUNTIF in Excel vs Google Sheets
Microsoft Excel (365 / Desktop)
The COUNTIF excel formula (count if) accepts cross-sheet references: =COUNTIF(Sheet2!B:B, "Shipped"). COUNTIFS has been available since Excel 2007. Whole-column refs are convenient and slower on large sheets than a bounded range.
Google Sheets
COUNTIF in Google Sheets — also searched as google sheets countif or google spreadsheet count if — uses the same syntax and wildcard rules as Excel. COUNTIFS is still AND logic. QUERY can group counts, but a single condition still belongs in COUNTIF.
COUNTIF exercises for this guide
COUNTIF exercises
Duplicate order IDs use an exact text criterion. Passing scores put the comparison operator inside the criteria string.
FAQ
How does the COUNTIF formula work in Excel (count if)?
=COUNTIF(range, criteria) walks range and counts every cell that meets criteria. Example: =COUNTIF(B2:B6, "Shipped") returns how many statuses equal Shipped. Text criteria and operators such as ">=60" stay inside quotes.
Does COUNTIF work in Google Sheets / Google Spreadsheet?
Yes. COUNTIF in Google Sheets uses the same syntax as Excel: =COUNTIF(range, criteria). Searches for google sheets countif or google spreadsheet count if point to this same function — wildcards and COUNTIFS AND logic match Excel.
How do I use Excel COUNTIF to count if not blank?
Use a not-equal criterion: =COUNTIF(A2:A10, "<>") counts every non-blank cell (text and numbers). =COUNTIF(A2:A10, "<>""") is the same idea with an empty-string comparison. Prefer COUNTA when you only need “anything filled”; use COUNTIF when the not-blank test must sit next to other criteria later in COUNTIFS.
How do I use IF and COUNTIF in Excel together?
Put COUNTIF inside IF when the count should choose a label: =IF(COUNTIF($A$2:$A$11, A2)>1, "Duplicate", "Unique"). IF handles the then/else; COUNTIF supplies the condition count.
What is the difference between COUNTIF and COUNTIFS?
COUNTIF accepts one condition. COUNTIFS accepts two or more, and a row counts only when every pair matches: =COUNTIFS(A2:A5, "North", B2:B5, "Shipped"). Unlike SUMIFS, COUNTIFS has no sum range — each argument is a range/criteria pair.
How do I count cells that contain text?
Use a wildcard: =COUNTIF(A2:A10, "*") is the usual way of counting text cells. Numbers and blanks do not match the asterisk. To require at least one character, use "?*". To count cells containing a word, use "*apple*". Matching is not case-sensitive.
How do I count duplicates with COUNTIF?
A helper column =COUNTIF($A$2:$A$11, A2) returns how many times the value in A2 appears. Values of 2 or more are duplicates. The same test, =COUNTIF($A$2:$A$11, A2)>1, is the custom formula behind highlight-duplicates rules.
Why does COUNTIF return 0?
Typical causes: text criteria without quotes, a number stored as text when the criterion is numeric, hidden spaces (clean them with TRIM), or a wildcard that does not match the way you expect. COUNTIF does not throw — it just counts zero matches.