Curious Minds

Clear answers to science and history questions

COUNTIF Cell Contains Specific Text: Excel Guide

· 5 min read · Science

To count cells that contain specific text in Excel, use the COUNTIF function with wildcards: =COUNTIF(range, "*text*"). The asterisks act as wildcards that match any characters before and after the text, so the formula counts every cell where the text appears anywhere inside the cell, regardless of what else the cell contains.

Why COUNTIF Needs Wildcards for Partial Matches

By default, COUNTIF matches the entire cell content. If you write =COUNTIF(A1:A10, "apple"), Excel counts only cells that contain exactly "apple" — not "apple pie", "pineapple", or "Apple" (unless case-insensitivity applies, which it does by default). To count cells that merely contain the text somewhere inside, you must wrap the search term in asterisks: "*apple*". This tells Excel to look for "apple" anywhere within the cell's text.

The asterisk (*) represents any number of characters, including zero. The question mark (?) represents exactly one character. So "*a?ple*" would match "apple" and "ample" but not "appple". These wildcards work in COUNTIF, SUMIF, and similar functions that accept criteria strings.

Step-by-Step: Counting Cells That Contain Text

  1. Select the cell where you want the result.
  2. Type =COUNTIF(.
  3. Select the range you want to search, for example A2:A100.
  4. Type a comma, then the criteria in quotes with wildcards: "*yourtext*".
  5. Close the parenthesis and press Enter.

Example: =COUNTIF(B2:B50, "*urgent*") counts every cell in B2:B50 that contains the word "urgent" anywhere in its text, including "urgent: review", "not urgent", and "URGENT".

Case Sensitivity and Exact Matches

COUNTIF is not case-sensitive. "Apple", "apple", and "APPLE" are treated the same. If you need a case-sensitive count, use SUMPRODUCT with the EXACT function or the FIND function, because COUNTIF cannot distinguish case.

To count cells that contain the text as a whole word only — not as part of a longer word — you need a different approach, because wildcards match substrings. For example, "*apple*" also counts "pineapple". To avoid that, you can use =COUNTIF(range, "apple") + COUNTIF(range, "apple *") + COUNTIF(range, "* apple") + COUNTIF(range, "* apple *"), but this gets cumbersome. A more robust method is SUMPRODUCT with ISNUMBER(SEARCH(" apple ", " "&range&" ")) to pad spaces around each cell and search for the word with spaces.

Common Problems and How to Fix Them

  • Wildcards not working: If your formula returns 0 unexpectedly, check whether the workbook is set to use regular expressions or whether wildcards have been disabled in Excel options. In some versions or configurations, wildcards may be turned off.
  • Counting numbers as text: COUNTIF with wildcards only works on text values. If cells contain numbers stored as numbers, "*1*" will not match them. Convert numbers to text or use a different criterion.
  • Leading/trailing spaces: Extra spaces in cells can prevent matches. Use TRIM in a helper column or incorporate it into a SUMPRODUCT formula.
  • Criteria length limit: COUNTIF criteria strings are limited to 255 characters. For longer text, use SUMPRODUCT with SEARCH.
  • Asterisk as literal: To search for an actual asterisk or question mark, precede it with a tilde (~). For example, "*~**" counts cells containing a literal asterisk.

Alternatives: When COUNTIF Isn't Enough

COUNTIF is simple and fast for basic substring counts, but it has limitations. For case-sensitive counting, use =SUMPRODUCT(--ISNUMBER(FIND("text", range))). For counting cells that contain any of multiple texts, you can sum several COUNTIFs or use SUMPRODUCT with multiple SEARCH conditions. For dynamic arrays in newer Excel versions, =SUM(--ISNUMBER(SEARCH("text", range))) works without wildcards and handles case sensitivity via FIND.

Another alternative is the FILTER function combined with COUNTA, but that is more for extracting lists than counting. For most users, COUNTIF with wildcards remains the quickest solution.

Practical Examples

Suppose column A contains product descriptions. To count how many contain "organic", use =COUNTIF(A:A, "*organic*"). To count cells that start with "organic", use "organic*". To count cells that end with "organic", use "*organic". To count cells that contain either "organic" or "natural", use =COUNTIF(A:A, "*organic*") + COUNTIF(A:A, "*natural*") — but be aware this double-counts cells containing both. To avoid double-counting, use =SUMPRODUCT(--(ISNUMBER(SEARCH("organic", A:A)) + ISNUMBER(SEARCH("natural", A:A)) > 0)).

For a list of items, you can build a small table of search terms and use COUNTIF with cell references: =COUNTIF($A$2:$A$100, "*"&D2&"*") where D2 holds the term. This makes it easy to count many terms without editing formulas.

Frequently Asked Questions

Can COUNTIF count cells that contain text but not a specific word?

Yes. Use =COUNTIF(range, "*text*") to count cells containing the text, then subtract from the total count of non-blank cells to get cells that do not contain it. Or use =COUNTIF(range, "<>*text*") to count cells that do not contain the text (this works in most Excel versions).

Does COUNTIF work with wildcards in all Excel versions?

Wildcards in COUNTIF are supported in Excel 2007 and later, and in most Excel 365 versions. However, some Excel options or settings (like "Use wildcards in formulas") can be disabled. In Excel for the web, wildcards work in COUNTIF as well.

How do I count cells that contain multiple specific words?

To count cells that contain both "red" and "blue", you can use =SUMPRODUCT(--ISNUMBER(SEARCH("red", range)), --ISNUMBER(SEARCH("blue", range))). COUNTIF alone cannot require two substrings in the same cell without helper columns or array formulas.

Why does my COUNTIF with wildcards return zero?

Common causes: the range contains numbers, not text; wildcards are disabled in Excel options; the text has leading/trailing spaces; or the criteria string is malformed (e.g., missing quotes). Check these first.

Can I use COUNTIF to count cells that contain a question mark?

Yes, but you must escape it with a tilde: "*~?*" counts cells containing a literal question mark. Without the tilde, the question mark acts as a wildcard for any single character.

Is COUNTIF case-sensitive?

No, COUNTIF is not case-sensitive. For case-sensitive counting, use SUMPRODUCT with FIND or EXACT.

In this article
  1. Why COUNTIF Needs Wildcards for Partial Matches
  2. Step-by-Step: Counting Cells That Contain Text
  3. Case Sensitivity and Exact Matches
  4. Common Problems and How to Fix Them
  5. Alternatives: When COUNTIF Isn't Enough
  6. Practical Examples
  7. Frequently Asked Questions