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.
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"countsapplebut notpineapple.~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*")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'sCOUNTIFignores 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. SUMPRODUCTand@cellare 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'sCOUNTIF- 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.
How do I count cells that contain specific text in Excel?
Why does my COUNTIF wildcard formula return 0?
How do I make COUNTIF case-sensitive?
How do I count cells that do NOT contain some text?
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.