Menu

Count Cells with Text in Excel (and If a Cell Contains Text)

=COUNTIF(A2:A8,"*") counts the cells in A2:A8 that hold text, skipping numbers, dates and empty cells. Count cells that contain a specific word, and return a value if a cell contains text.

Every sheet on this page is live: change a number or a formula and it recalculates.

=COUNTIF(A2:A8,"*") counts the cells in A2:A8 that contain text. The asterisk is a wildcard for "any characters", and it only matches text, so numbers, dates, TRUE/FALSE and empty cells are not counted.

Count text cells
D2
ABCD
1EntryWhatCount
2AppleText3
312Not empty6
4Numbers and dates2
5PearEmpty1
62026-01-05
7TRUE
8n/a
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

D2 counts Apple, Pear and n/a: 3. COUNTA counts every filled cell, 6, and COUNT the two numbers (a date is a number). Type 25 into A4 and D3 and D4 go up while D2 stays at 3; type Plum instead and D2 and D3 go up while D4 stays at 2. COUNT and COUNTA are compared on their own page.

A number typed with an apostrophe in front, such as '007, is text, so "*" counts it. To count only cells with at least one character, use "?*": the ? must match one character, so a formula that returns an empty string ("") is never counted.

Count cells that contain specific text

To count cells that contain a word anywhere, put an asterisk on both sides of it. Without the asterisks, the whole cell has to match.

Count a word
D2
ABCD
1ProductConditionCount
2Applecontains apple5
3Pineappleexactly apple1
4Pearstarts with apple3
5apple juiceword in C61
6Plumjuice
7Green appleapple, case-sensitive3
8Apple cider
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

"*apple*" matches five products. "apple" alone matches only the cell that is exactly Apple (COUNTIF ignores case), and "apple*" the three that start with it. D5 takes the word from C6, so you can type any word there. D7 is case-sensitive: FIND, unlike COUNTIF, tells apple from Apple, so only Pineapple, apple juice and Green apple count. The -- turns the TRUE/FALSE results into 1 and 0 for SUMPRODUCT to add.

If a cell contains text, then return a value

To mark each row, test one cell at a time. SEARCH("apple",A2) returns the position where apple starts, or #VALUE! when it is not there. ISNUMBER turns that into TRUE or FALSE, and IF picks the result.

If cell contains apple
B2
ABC
1ProductContains apple?Any text?
2AppleYesText
3PearNoText
4PineappleYesText
542NoNot text
6Green appleYesText
72026-02-01NoNot text
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Both columns are filled down. B shows Yes for Apple, Pineapple and Green apple. C uses ISTEXT, which answers a different question: is there text in the cell at all. 42 and the date are numbers, so they are "Not text". Use FIND in place of SEARCH when case matters. More on the two functions, and why SEARCH is the one that ignores case, is on FIND and SEARCH.

=IF(COUNTIF(A2,"*apple*"),"Yes","No") does the same test with COUNTIF: a count of 1 counts as TRUE and 0 as FALSE.

Count cells that contain one of several words

Adding two COUNTIFs counts a cell twice when it contains both words. Test each cell once instead: SEARCH for each word, add the TRUE results, and count the rows where the sum is above 0.

Apple or juice
D2
ABCD
1ProductFormulaCount
2AppleTwo COUNTIFs5
3Orange juiceEach cell once4
4Pear
5apple juice
6Plum
7Green apple
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Four products mention apple or juice, but the two COUNTIFs give 5, because apple juice is counted by both. The SUMPRODUCT version gives 4.

Practice: count the text cells

Your turn: count the text
E2
ABCDE
1DeliveryWeightWhatCount
2D-112Notes
3D-29
4D-3damaged
5D-415
6D-5missing
7D-6
8D-7late
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: Some deliveries have a weight, others a note. Count the cells in B2:B8 that contain text. Write the formula in E2.

Why the count of text cells is off

  • Numbers stored as text are counted. A column imported from another system may hold '125 as text. "*" counts it, and COUNT does not. If COUNT on a column of numbers is lower than COUNTA, some of them are text; see numbers stored as text.
  • Cells that only look empty. A cell with a space in it is text and is counted. Use =SUMPRODUCT(--(LEN(TRIM(A2:A8))>0)) to count cells with visible characters.
  • TRUE and FALSE are not text. "*" skips them, as it skips error values like #N/A.
  • COUNTIF ignores case. For a case-sensitive count use FIND inside SUMPRODUCT, as in the second sheet.

Frequently Asked Questions

How do I count cells that contain any text in Excel?

Use =COUNTIF(A2:A8,"*"). The asterisk matches any text, so the formula counts every text cell and skips numbers, dates, TRUE/FALSE and empty cells.

How do I count cells that contain specific text?

Put asterisks around the word: =COUNTIF(A2:A8,"*apple*") counts cells with apple anywhere in them, in any case. Without the asterisks, "apple" counts only cells that are exactly apple.

How do I write "if cell contains text then" in Excel?

Combine IF, ISNUMBER and SEARCH: =IF(ISNUMBER(SEARCH("apple",A2)),"Yes","No"). SEARCH returns a position when it finds the text and an error when it does not, and ISNUMBER turns that into TRUE or FALSE.

How do I check if a cell contains any text at all?

Use =ISTEXT(A2), which is TRUE for text and FALSE for numbers, dates and empty cells. Inside IF: =IF(ISTEXT(A2),"Text","Not text").

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED