Excel guide · 4 min read
COUNTIF not working: causes and fixes
=COUNTIF(A2:A7,"Router") counts 0 when cells say "Router X2". Use wildcards for partial matches ("*Router*"), clean hidden spaces with TRIM, and switch to SUMPRODUCT for long ID numbers or criteria over 255 characters, where COUNTIF miscounts.Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Product | Status | SIM number | Grade | |
| 2 | Router X2 | Open | 8944100012345678901 | A* | |
| 3 | Router X2 | Closed | 8944100012345678902 | A | |
| 4 | Mesh Kit 3-pack | Open | 8944100012345678903 | B | |
| 5 | Router X4 | open | 8944100098765432101 | A* | |
| 6 | Range Extender | Closed | 8944100098765432102 | C | |
| 7 | Mesh Kit 2-pack | Pending | 8944100098765432103 | A |
Cause 1: you need a partial match
COUNTIF compares the whole cell with the criteria. A support log where products are called "Router X2" and "Router X4" has no cell that equals "Router", so =COUNTIF(A2:A7,"Router") returns 0.
Add wildcards. * stands for any number of characters, ? for exactly one. "Router*" means starts with Router; "*Kit*" means contains Kit anywhere. With a cell, join the wildcards on: =COUNTIF(A2:A7,"*"&G2&"*").
Result: 3
Three products start with Router, so the count is 3.
Cause 2: hidden spaces
A3 holds "Router X2 " with a trailing space, so =COUNTIF(A2:A7,"Router X2") returns 1 instead of 2. =LEN(A3) gives 10 for a 9-character name.
The proper fix is to clean the column with TRIM (helper column, fill down, paste as values). If you cannot touch the data, SUMPRODUCT can trim each cell while it counts. Avoid fixing this with "Router X2*": it would also count a future "Router X2 Pro".
Result: 2
With the trailing space trimmed, both Router X2 tickets are counted: 2.
Cause 3: your data contains * or ?
Because * and ? are wildcards, COUNTIF reads them as patterns even when you mean the characters. UK exam grades include A*, and =COUNTIF(E2:E7,"A*") counts everything that starts with A, giving 4 instead of 2.
Put a tilde (~) in front of a wildcard character to make it literal: "A~*" means the text A*. Use "~?" for a real question mark and "~~" for a real tilde. To count exactly "A" and nothing else, "A" on its own already works.
Result: 2
The tilde makes * literal, so only the two A* grades are counted: 2.
Cause 4: long numbers and numbers stored as text
COUNTIF turns anything that looks like a number into a number before comparing. Excel only keeps 15 significant digits, so 19- and 20-digit values like SIM card numbers, card numbers or tracking codes are compared on their first 15 digits. C2, C3 and C4 differ only in the last digits, and COUNTIF says each appears 3 times. A duplicate check built on it flags every one.
The same conversion means COUNTIF counts the text "1001" and the number 1001 as equal. That helps with mixed data, but comparison criteria like ">100" only see real numbers, so convert text numbers before counting ranges. For long IDs, compare directly with SUMPRODUCT, which keeps them as text. Another common workaround is =COUNTIF(C2:C7,C2&"*"), which forces a text comparison but also counts longer IDs that start with the same digits.
Result: 3
Wrongly returns 3: the first three SIM numbers share their first 15 digits. =SUMPRODUCT(--(C2:C7=C2)) gives the correct 1.
Cause 5: criteria longer than 255 characters
COUNTIF and the other IF-family functions (SUMIF, COUNTIFS, AVERAGEIF) cannot match criteria longer than 255 characters. Microsoft documents that the result is wrong; in practice you usually see #VALUE!. It shows up when counting long product descriptions, survey comments or URLs.
Use SUMPRODUCT with a direct comparison, which has no such limit: =SUMPRODUCT(--(D2:D500=G2)). Add TRIM inside if the text was pasted from elsewhere.
- Check the length of the criteria with
=LEN(G2). Over 255 means COUNTIF will not work. - Replace
=COUNTIF(D2:D500,G2)with=SUMPRODUCT(--(D2:D500=G2)). - For a contains-style match on long text, use
=SUMPRODUCT(--ISNUMBER(SEARCH(G2,D2:D500))).
Other reasons COUNTIF gives the wrong number
Operators must be in quotes and joined to cells with &: ">"&F2, not ">F2" (which counts cells greater than the text F2). COUNTIF is not case-sensitive, so "Open" also counts "open": =COUNTIF(B2:B7,"Open") returns 3 here, including the lowercase B5.
COUNTIF pointing at another workbook returns #VALUE! when that workbook is closed. And a range that slides when you copy the formula down drops rows; lock it with $A$2:$A$7.
Result: 3
3: COUNTIF ignores case, so "open" in B5 is counted with the two "Open" tickets.
Common mistakes
Expecting COUNTIF to find words inside cells
Wrap the word in wildcards: "*"&G2&"*".
Using COUNTIF to find duplicate long IDs
Numbers over 15 digits are compared on the first 15 only. Use SUMPRODUCT(--(range=cell)).
Searching for a literal * or ?
Escape it with a tilde: "A~*" or "~?".
Fixing spaces with wildcards
"Name*" over-matches. TRIM the data, or use SUMPRODUCT with TRIM.
FAQ
Why is my COUNTIF returning 0?
No cell matches the criteria exactly. The cells usually contain more text than the criteria (use wildcards), have hidden spaces (use TRIM), or the criteria has a cell reference inside quotes.
How do I count cells that contain a word in Excel?
Use =COUNTIF(A2:A100,"*word*"). The asterisks mean any characters before or after the word. COUNTIF ignores case.
Why does COUNTIF count different long numbers as the same?
COUNTIF converts numeric text to numbers, and Excel keeps only 15 digits, so long IDs that share the first 15 digits look equal. Use =SUMPRODUCT(--(A2:A100=A2)).
Is there a character limit for COUNTIF criteria?
Yes. COUNTIF cannot match criteria longer than 255 characters. Use SUMPRODUCT with a direct comparison for long text.
Can COUNTIF be case-sensitive?
No. For a case-sensitive count, use SUMPRODUCT with EXACT: =SUMPRODUCT(--EXACT(A2:A100,"Open")).
Functions used
COUNTIFCounts cells that matchSUMPRODUCTMultiply then addTRIMRemoves extra spacesLENLength of textISNUMBERIs it a number?SEARCHPosition of text
Related guides
- COUNTIFS with multiple criteria in Excel
- How to count cells with text in Excel
- How to remove spaces in Excel
- SUMIF returning 0 or not working: causes and fixes
- Attendance tracker formulas in Excel
- VLOOKUP not working: 7 causes and fixes
- FIND vs SEARCH in Excel
Updated