Cellwise Try it free

Excel guide · 4 min read

COUNTIF not working: causes and fixes

Quick answerCOUNTIF matches the whole cell, so =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.

ABCDE
1ProductStatusSIM numberGrade
2Router X2Open8944100012345678901A*
3Router X2 Closed8944100012345678902A
4Mesh Kit 3-packOpen8944100012345678903B
5Router X4open8944100098765432101A*
6Range ExtenderClosed8944100098765432102C
7Mesh Kit 2-packPending8944100098765432103A

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&"*").

=COUNTIF(A2:A7,"Router*")

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".

=SUMPRODUCT(--(TRIM(A2:A7)="Router X2"))

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.

=COUNTIF(E2:E7,"A~*")

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.

=COUNTIF(C2:C7,C2)

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.

  1. Check the length of the criteria with =LEN(G2). Over 255 means COUNTIF will not work.
  2. Replace =COUNTIF(D2:D500,G2) with =SUMPRODUCT(--(D2:D500=G2)).
  3. 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.

=COUNTIF(B2:B7,"Open")

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

Related guides

Updated