How-to recipes · Counting and summing

How to count cells that contain text in Excel

Count cells that hold any text, or that contain a specific word anywhere, with COUNTIF wildcards, SEARCH and ISNUMBER; plus a case-sensitive version.

Beginner COUNTIF COUNTIFS SEARCH FIND ISNUMBER ISTEXT SUMPRODUCT SUM COUNTA

"Count the cells that contain text" can mean two different things. Either you want to know how many cells hold any text at all (as opposed to numbers or blanks), or you want to know how many cells contain a particular word, such as how many support tickets mention refund. Both are one-line formulas, but each has a trap: the first can count cells that only look empty, the second must find the word anywhere inside a longer sentence. This recipe covers both.

The example data

Eight ticket subjects in A2:A9. One cell (A6) holds a number that was typed by mistake, and A7 is empty.

Count cells that contain any text

The wildcard * means any sequence of characters. COUNTIF with "*" counts cells that contain text and skips numbers and empty cells:

C2fx=COUNTIF(A2:A9,"*")
ABC
1Ticket subject
2Refund request for order 55126
3Login problem
4Partial refund
5Shipping delay
61042
7
8REFUND not received
9Change address

The number 1042 and the empty cell are not counted.

Result: 6

Compare it with COUNTA, which counts every non-empty cell, numbers included: =COUNTA(A2:A9) returns 7. An alternative that makes the intent explicit is =SUMPRODUCT(--ISTEXT(A2:A9)), using ISTEXT.

Watch out. Cells containing a formula that returns an empty text ("") look blank but are counted by "*", and cells holding a single space are counted too. To count only cells with at least one visible character, use =COUNTIF(A2:A9,"?*"); the ? requires at least one character, which rules out formula blanks.

Count cells that contain a specific word

Put the wildcard on both sides of the word to find it anywhere in the cell:

C2fx=COUNTIF(A2:A9,"*refund*")
ABC
1Ticket subject
2Refund request for order 55123
3Login problem
4Partial refund
5Shipping delay
61042
7
8REFUND not received
9Change address

Matches "Refund request...", "Partial refund" and "REFUND not received". COUNTIF ignores case.

Result: 3

With the word in a cell, say C1, join the wildcards to it: =COUNTIF(A2:A9,"*"&C1&"*"). Leave out the first * to count cells that start with the word, or the last one for cells that end with it.

Several conditions

COUNTIFS combines conditions with AND: tickets that mention refund but not partial: =COUNTIFS(A2:A9,"*refund*",A2:A9,"<>*partial*") returns 2. For OR logic, add two COUNTIFs, but subtract cells that match both so they are not counted twice.

Microsoft 365: SEARCH on the whole range

SEARCH returns the position of a word inside a text, or #VALUE! if it is missing. ISNUMBER turns that into TRUE/FALSE, and SUM counts the TRUEs:

Formula
=SUM(--ISNUMBER(SEARCH("refund",A2:A9)))

It returns 3, like COUNTIF. The advantage is flexibility: the same pattern works with any test, for example several words at once: =SUM(--(ISNUMBER(SEARCH("refund",A2:A9))+ISNUMBER(SEARCH("return",A2:A9))>0)). In Excel 2016 and 2019, use SUMPRODUCT instead of SUM so you do not need Ctrl+Shift+Enter.

Case-sensitive count

COUNTIF and SEARCH ignore case. FIND does not, so swap it in when case matters:

C2fx=SUMPRODUCT(--ISNUMBER(FIND("refund",A2:A9)))
ABC
1Ticket subject
2Refund request for order 55121
3Login problem
4Partial refund
5Shipping delay
61042
7
8REFUND not received
9Change address

Only "Partial refund" contains refund in lower case.

Result: 1

Pitfalls

  • Partial words. *cat* also matches category and education. To match a whole word in a sentence, add spaces around the cell and the word: =COUNTIF(A2:A9,"* cat *") misses the first and last word, so use =SUM(--ISNUMBER(SEARCH(" cat "," "&A2:A9&" "))).
  • Wildcard characters in your search term. To count cells that contain a real asterisk or question mark, escape it with a tilde: "*~**".
  • Numbers are not text. =COUNTIF(A2:A9,"*104*") does not count the number 1042, because wildcards only work on text. The SEARCH version does find it.
  • 255-character limit. COUNTIF criteria longer than 255 characters return #VALUE!; SEARCH has no such problem.

Which formula to use

For a quick count of one word, COUNTIF with wildcards is the shortest and fastest formula and works in every version. Switch to SEARCH or FIND when you need case sensitivity, whole-word matching, several alternative words, or when the cells may contain numbers. Keep the search term in its own cell so that colleagues can change it without editing the formula.

Tip. To check a single cell rather than count a range, see How to check if a cell contains a word in Excel. To count by colour rather than content, see How to count cells by color in Excel. All COUNTIF variations are in Counting and summing with criteria: COUNTIFS, SUMIFS, SUMPRODUCT.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

More how-to recipes