COUNTIF Contains Text: Fix Wrong Partial-Match Counts

Count cells containing text in Excel and Google Sheets, then fix wrong totals caused by blank search terms, numbers, overlapping matches, and wildcards.

On this page

You need to count support notes that mention refund, but an exact-match COUNTIF gives you zero. A partial-match count finds the notes, although it also picks up words such as nonrefundable that you might not want.

Here’s the ticket-notes column. Put Note in A1 and enter the following values in A2:A11; leave A7 genuinely empty and type A8 as the number 1500.

CellNote
A2Customer asked for refund
A3Customer requested a return
A4REFUNDED yesterday
A5Item marked nonrefundable
A6Refund and return both mentioned
A7
A81500
A9Customer typed * in the notes
A10Is a refund? still possible
A11Delivery rescheduled

In Excel or Google Sheets, this counts the cells containing refund anywhere:

=COUNTIF(A2:A11,"*refund*")

It returns 5: A2, A4, A5, A6, and A10. The asterisks allow characters before and after refund, and COUNTIF isn’t case-sensitive. It counts REFUNDED and nonrefundable because this is a substring test, not a whole-word test.

Google Sheets with D3 selected, showing =COUNTIF(A2:A11,"*refund*") in the formula bar and a result of 5, with refund in E1.
Screenshot: Google Sheets, Nov 2026

When the search word comes from another cell

Type refund in E1, then use:

=COUNTIF(A2:A11,"*"&E1&"*")

That also returns 5. The ampersands join the wildcard characters to the text in E1.

If E1 is empty, the criterion becomes just *. On this sample it returns 8, counting every text cell rather than returning zero. Guard the search box:

=IF(E1="","",COUNTIF(A2:A11,"*"&E1&"*"))

With E1 empty, this shows a blank; with refund in E1, it shows 5. I prefer this version for a report with an editable search cell. An empty input shouldn’t silently turn into a count of unrelated notes.

Why a number containing 15 is missed

Change E1 to 15. A8 displays 1500, but a wildcard criterion looks for text, not a numeric value:

=COUNTIF(A2:A11,"*15*")

This returns 0. When I stored the same 1500 as text, the same formula returned 1. If imported IDs arrive as text, wildcard COUNTIF will start counting them; converting text to numbers covers how to tell the two apart.

Google Sheets with D8 selected, showing =COUNTIF(A2:A11,"*15*") in the formula bar and a result of 0 for the numeric 1500 in A8; the SEARCH-based count in the next row returns 1.
Screenshot: Google Sheets, Nov 2026

To search the text representation of numbers as well, use:

=IF(E1="","",SUMPRODUCT(--ISNUMBER(SEARCH(E1,A2:A11))))

With 15 in E1, this returns 1, counting A8. With refund in E1, it returns 5. SEARCH checks each cell, including the numeric 1500, which it treated as the text 1500 and matched at position 1. ISNUMBER turns a found position into TRUE, and SUMPRODUCT adds the matches. SEARCH ignores case. On the blank in A7, SEARCH returned #VALUE! and ISNUMBER of that result was FALSE, so the blank did not break the count.

Refund OR return without counting one note twice

Suppose either term should qualify. Adding two COUNTIF results looks reasonable:

=COUNTIF(A2:A11,"*refund*")+COUNTIF(A2:A11,"*return*")

It returns 7: five refund matches plus two return matches. But A6 mentions both, so there are only six distinct matching cells. This is an OR condition; COUNTIFS is designed for AND conditions. For a closer comparison, see COUNTIF vs COUNTIFS vs SUMPRODUCT.

I would count each row’s combined test instead:

=SUMPRODUCT(--((ISNUMBER(SEARCH("refund",A2:A11))+ISNUMBER(SEARCH("return",A2:A11)))>0))

This returns 6. The >0 turns a row with either match, or both, into a single TRUE.

In Google Sheets, a regular expression is shorter:

=SUMPRODUCT(--REGEXMATCH(A2:A11&"","(?i)(refund|return)"))

This also returns 6. | means OR, (?i) ignores case, and &"" converts the numeric cell to text. Without that concatenation, REGEXMATCH(A8,"15") returned #VALUE!. COUNTIF itself does not accept a regular expression: in this test, =COUNTIF(A2:A11,"refund|return") returned 0. Unlike COUNTIF, Google Sheets REGEXMATCH is the function that takes a regular expression.

A whole word is not the same as a partial match

The original five include REFUNDED and nonrefundable. If you mean the word refund, an Excel workaround is to add spaces on both sides of every note and search for spaces around the word:

=SUMPRODUCT(--ISNUMBER(SEARCH(" refund "," "&A2:A11&" ")))

It returns 2, finding A2 and A6. It misses A10, because refund? has a question mark rather than a space after the word. It also treats hyphens and other punctuation as part of the surrounding text. For clean, space-separated labels, this is adequate; for customer messages, it’s a compromise.

Google Sheets can recognize word boundaries:

=SUMPRODUCT(--REGEXMATCH(A2:A11&"","(?i)\brefund\b"))

It returns 3, including A10 but excluding REFUNDED and nonrefundable. A regex word boundary has its own rules: in this test, refund-related also matched, because the hyphen counts as a boundary. Check examples like that against the meaning you need.

If case matters rather than word boundaries, replace SEARCH with FIND:

=SUMPRODUCT(--ISNUMBER(FIND("refund",A2:A11)))

This returns 3: A2, A5, and A10. FIND rejects REFUNDED and Refund and return both mentioned, but it still matches nonrefundable. The distinction between FIND and SEARCH matters here: case sensitivity doesn’t make a substring into a whole word.

When * or ? is the character you’re looking for

A9 contains a literal asterisk and A10 a literal question mark. COUNTIF treats those characters as wildcards unless you escape them with a tilde:

=COUNTIF(A2:A11,"*~**")

This returns 1, for A9. To find the literal question mark:

=COUNTIF(A2:A11,"*~?*")

This returns 1, for A10. In this Google Sheets test, SEARCH also treated * and ? as wildcards. SEARCH("*",A9) returned 1, the first character, while SEARCH("~*",A9) returned 16, the actual asterisk. The same pair on A10 returned 1 and 12. SUMPRODUCT(--ISNUMBER(SEARCH("*",A2:A11))) returned 9, one for every non-blank cell. If the search text might contain * or ?, escape them in SEARCH as well as in COUNTIF.

One last distinction matters when you’re checking a suspicious total: =COUNTIF(A2:A11,"*") returns 8 for the text cells, whereas =COUNTIF(A2:A11,"<>") returns 9 because it also includes numeric A8. If I replaced the empty A7 with a formula that returned "", "*" became 9 and "<>" became 10. That cell still looked empty: LEN was 0, ISTEXT was TRUE, and ISBLANK was FALSE. Formula-produced empty strings need that separate check; see ISBLANK vs empty.

Oscar

Spreadsheet nerd who writes about Excel and Google Sheets formulas.

Google Sheets, 15 November 2026, tab count-contains-text. Exact COUNTIF of refund returned 0. COUNTIF *refund* and "*"&E1&"*" with refund in E1 both returned 5 (A2, A4, A5, A6, A10), including REFUNDED and nonrefundable. Empty E1 made the criterion * and returned 8; IF(E1="","",COUNTIF(...)) returned a blank, and 5 with refund. COUNTIF *15* returned 0 on numeric 1500 (ISNUMBER TRUE) and 1 when 1500 was stored as text. SUMPRODUCT(--ISNUMBER(SEARCH(E1,A2:A11))) returned 1 for 15 and 5 for refund; SEARCH("15",A8) and FIND("15",A8) both returned 1; SEARCH("refund",A7) was #VALUE! and ISNUMBER of that was FALSE. COUNTIF*refund* plus COUNTIF*return* returned 7; SUMPRODUCT of a combined SEARCH test and SUMPRODUCT(--REGEXMATCH(A2:A11&"","(?i)(refund|return)")) both returned 6. REGEXMATCH(A8,"15") was #VALUE!; COUNTIF of refund|return returned 0. Space-padded SEARCH(" refund "," "&range&" ") returned 2 (A2, A6) and missed refund?. REGEXMATCH (?i)\brefund\b returned 3, including A10, and was TRUE for refund-related. FIND("refund",range) returned 3 (A2, A5, A10); FIND was FALSE on REFUNDED and TRUE on nonrefundable. COUNTIF *~** and *~?* each returned 1. SEARCH("*",A9) returned 1 and SEARCH("~*",A9) returned 16; SEARCH("?",A10) returned 1 and SEARCH("~?",A10) returned 12. SUMPRODUCT of SEARCH("*") or SEARCH("?") returned 9; the escaped versions returned 1. COUNTIF "*" returned 8 and "<>" returned 9; COUNTA 9, COUNT 1, COUNTBLANK 1. Replacing the blank with a formula "" made "*" return 9 and "<>" return 10; that cell had LEN 0, ISTEXT TRUE, ISBLANK FALSE, and COUNTBLANK counted it. Excel was not re-run.

Next in Lookup & Conditional Sums SUMIFS Between Two Dates Returns the Wrong Total