Formula guide

Count if a cell contains text in Excel

You have a column of free-typed text and one question: how many of these mention "invoice"? One COUNTIF with wildcards answers it. This page covers that formula, the wildcard rules, the case-sensitive variant, and the multi-condition counts, each as a copyable block.

5 min readCopyable formulas

The quick answer: COUNTIF with wildcards

Wrap the text in * wildcards. *invoice* means "anything, then invoice, then anything", i.e. contains:

=COUNTIF(A2:A20, "*invoice*")

Worked example: in a task list containing Send invoice to Apple, invoice reminder, and Design review, the formula returns 2.

Excel's COUNTIF matching is case-insensitive: *invoice* also counts Invoice and INVOICE. It matches text values only; a number in the range is not counted by a wildcard pattern.

The wildcard rules

COUNTIF (and SUMIF/COUNTIFS/AVERAGEIF) understand three special characters:

  • * matches any run of characters, including none. "invoice*" = starts with, "*invoice" = ends with, "*invoice*" = contains.
  • ? matches exactly one character. "?pple" counts apple but not pineapple.
  • ~ escapes a literal asterisk or question mark: "~*" counts cells that actually contain a * character.

Take the search text from another cell

Concatenate the wildcards around a cell reference, so changing B1 re-runs the count without editing the formula:

=COUNTIF(A2:A20, "*" & B1 & "*")

Count cells that contain ANY text

A bare * counts every cell whose value is text (numbers and blanks are not counted). Compare it with COUNTA, which counts every non-empty cell of any type:

=COUNTIF(A2:A20, "*")
=COUNTA(A2:A20)

Case-sensitive count: SUMPRODUCT + ISNUMBER + FIND

COUNTIF cannot tell Invoice from invoice. For an exact-case count, test each cell with FIND (which is case-sensitive), convert the found/not-found results to 1s and 0s, and add them up:

=SUMPRODUCT(--ISNUMBER(FIND("Invoice", A2:A20)))

FIND returns a position when the text is found and an error when it is not; ISNUMBER turns that into TRUE/FALSE; the double minus -- turns TRUE/FALSE into 1/0; SUMPRODUCT adds them. Swap FIND for SEARCH and the same structure becomes a case-insensitive contains-count without wildcards, useful when your search text itself contains * or ?.

Contains X and Y, or X or Y

Stack conditions with COUNTIFS (all conditions must hold on the same row):

=COUNTIFS(A2:A20, "*invoice*", A2:A20, "*paid*")

For OR, add the two counts and subtract the overlap so rows containing both are not double-counted:

=COUNTIF(A2:A20, "*invoice*") + COUNTIF(A2:A20, "*receipt*")
 - COUNTIFS(A2:A20, "*invoice*", A2:A20, "*receipt*")
And in a shared grid

The same formula in Wisegrid

Wisegrid's formula engine ships COUNTIF, COUNTIFS, SUMIF, FIND, ISNUMBER, IF, LOWER, and SUM, and COUNTIF's wildcard matching now works exactly like Excel's: case-insensitive, and anchored to where the * sits in the pattern. The headline formula, which is the whole point of this page, runs unchanged in a shared Wisegrid grid:

=COUNTIF(A:A, "*invoice*")

Whole-column letter ranges like A:A work directly, and same-row references use the column name: [Task]@row. Two things that used to differ from Excel now match it exactly, and one real gap remains:

  • Case: "*invoice*" and "*Invoice*" return the same count (verified against the shipped engine) - Wisegrid's COUNTIF ignores case, same as Excel. The LOWER + FIND helper column below still works; it is just no longer required for a case-insensitive count.
  • Anchoring: "invoice*" counts only cells that start with "invoice", "*invoice" only cells that end with it, and "*invoice*" counts cells that contain it anywhere - the same three patterns, anchored the same way, as Excel (verified against the shipped engine). ? still matches exactly one character. The LEFT/RIGHT helper-column pattern below still works too, for the same reason: no longer required, still useful.
  • SUMPRODUCT and @cell are not in Wisegrid's supported set, so the array-style one-liner still does not port, and the ~ escape for a literal * or ? is not implemented in Wisegrid's COUNTIF - do not rely on "~*" to search for a literal asterisk. The Wisegrid equivalent for the SUMPRODUCT case is a helper column plus SUM, which also reads more plainly in a shared grid:
Same task list, testing the anchors directly - each pattern below differs from the headline formula by one wildcard:
=COUNTIF(A:A, "invoice*")
=COUNTIF(A:A, "*invoice")

Against Send invoice to Apple and Design review, both anchored patterns return 0: neither task literally starts or ends with "invoice", so only the contains pattern this page opened with matches. That is the anchoring working as advertised, and it is also why the helper-column patterns below are no longer required for a correct count, only still useful: COUNTIF now does the case-insensitive, anchored matching natively. A helper column still earns its keep when you want the match visible as its own grid column, and Wisegrid also ships Smartsheet's CONTAINS(text, value) (still case-sensitive, unaffected by this fix), so Smartsheet-style formulas keep working after an import.

The helper-column pattern below runs the same strict starts-with or ends-with count with LEFT or RIGHT, if you would rather see the check as its own column than as a bare COUNTIF:

Starts-with helper column, as a column formula:
=IF(LEFT([Order Id]@row, 3) = "INV", 1, 0)

Ends-with helper, same pattern with RIGHT:
=IF(RIGHT([Order Id]@row, 5) = "00482", 1, 0)

The count, either way:
=SUM([Helper]:[Helper])

Worked example: with INV-00482 and INV-00483 in the Order Id column, the starts-with helper marks both rows 1 (both begin INV), so SUM returns 2; the ends-with helper marks only the row ending 00482, so SUM returns 1. The native anchored wildcards agree: =COUNTIF(C:C, "INV*") also returns 2, and =COUNTIF(C:C, "*00482") also returns 1 (Order Id is column C in this example).

Verified against the shipped engine: the case-insensitive contains wildcard, the anchored starts-with/ends-with wildcards, the LOWER/FIND helper, the LEFT/RIGHT helper, and CONTAINS were each executed against the live 118-function engine before publishing.

Frequently asked
How do I count cells that contain specific text in Excel?
Use COUNTIF with the text wrapped in asterisks: =COUNTIF(A2:A20, "*invoice*"). The * wildcard matches anything before and after, so the formula counts every cell that contains "invoice" anywhere, ignoring case.
Why does my COUNTIF wildcard formula return 0?
The usual causes: the range contains numbers rather than text (wildcards only match text values); the search text has a typo or an invisible character such as a non-breaking space; or you searched for a literal * or ? without escaping it as ~* or ~?.
How do I make COUNTIF case-sensitive?
COUNTIF itself cannot be. Use =SUMPRODUCT(--ISNUMBER(FIND("Text", A2:A20))) instead: FIND is case-sensitive, ISNUMBER converts its result to TRUE/FALSE, and SUMPRODUCT totals the matches.
How do I count cells that do NOT contain some text?
Use the <> operator with the wildcard pattern: =COUNTIF(A2:A20, "<>*invoice*") counts cells that do not contain "invoice", including blanks. Subtract COUNTBLANK(A2:A20) if you want only non-empty non-matches.

Formulas that work where your team does.

Wisegrid is the familiar grid with a 118-function formula engine, shared editing, and views your stakeholders can actually read. Start your 7-day free trial, and if you are coming from Smartsheet, bring your workspace with you.