How to count cells with text in Excel: any, specific, filtered cells

How do I count cells with text in Excel? There are a few different formulas to count cells that contain any text, specific characters or only filtered cells. All the formulas work in Excel 365, 2021, 2019, 2016, 2013 and 2010.

Initially, Excel spreadsheets were designed to work with numbers. But these days we often use them to store and manipulate text too. Want to know how many cells with text there are in your worksheet? Microsoft Excel has several functions for this. Which one should you use? Well, it depends on the situation. In this tutorial, you will find a variety of formulas and when each formula is best to be used.

How to count number of cells with text in Excel

There are two basic formulas to find how many cells in a given range contain any text string or character.

COUNTIF formula to count all cells with text

When you wish to find the number of cells with text in Excel, the COUNTIF function with an asterisk in the criteria argument is the best and easiest solution:

COUNTIF(range, "*")

Because the asterisk (*) is a wildcard that matches any sequence of characters, the formula counts all cells that contain any text.

SUMPRODUCT formula to count cells with any text

Another way to get the number of cells containing text is to combine the SUMPRODUCT and ISTEXT functions:

SUMPRODUCT(--ISTEXT(range))

Or

SUMPRODUCT(ISTEXT(range)*1)

The ISTEXT function checks if each cell in the specified range contains any text characters and returns an array of TRUE (cells with text) and FALSE (other cells) values. The double unary (--) or the multiplication operation coerces TRUE and FALSE into 1 and 0, respectively, producing an array of ones and zeros. The SUMPRODUCT function sums all the elements of the array and returns the number of 1's, which is the number of cells that contain text.

To gain more understanding of how these formulas work, please see which values are counted and which are not:

What is counted What is not counted
  • Cells with any text
  • Special characters
  • Numbers formatted as text
  • Visually blank cells that contain an empty string (""), apostrophe ('), space or non-printing characters
  • Numbers
  • Dates
  • Logical values of TRUE and FALSE
  • Errors
  • Blank cells

For example, to count cells with text in the range A2:A10, excluding numbers, dates, logical values, errors and blank cells, use one of these formulas:

=COUNTIF(A2:A10, "*")

=SUMPRODUCT(--ISTEXT(A2:A10))

=SUMPRODUCT(ISTEXT(A2:A10)*1)

The screenshot below shows the result:
Excel formula to count cells with text

Count cells with text excluding spaces and empty strings

The formulas discussed above count all cells that have any text characters in them. In some situations, however, that might be confusing because certain cells may only look empty but, in fact, contain characters invisible to the human eye such as empty strings, apostrophes, spaces, line breaks, etc. As a result, a visually blank cell gets counted by the formula causing a user to pull out their hair trying to figure out why :)

To exclude "false positive" blank cells from the count, use the COUNTIFS function with the "excluded" character in the second criterion.

For example, to count cells with text in the range A2:A7 ignoring those that contain a space character, use this formula:

=COUNTIFS(A2:A7,"*", A2:A7, "<> ")
Formula to count cells with text excluding cells that contain spaces

If your target range contains any formula-driven data, some of the formulas may result in an empty string (""). To ignore cells with empty strings too, replace "*" with "*?*" in the criteria1 argument:

=COUNTIFS(A2:A9,"*?*", A2:A9, "<> ")

A question mark surrounded by asterisks indicates that there should be at least one text character in the cell. Since an empty string has no characters in it, it does not meet the criteria and is not counted. Blank cells that begin with an apostrophe (') are not counted either.

In the screenshot below, there is a space in A7, an apostrophe in A8 and an empty string (="") in A9. Our formula leaves out all those cells and returns a text-cells count of 3:
Count cells with text excluding spaces and empty strings

How to count cells with certain text in Excel

To get the number of cells that contain certain text or character, you simply supply that text in the criteria argument of the COUNTIF function. The below examples explain the nuances.

To match the sample text exactly, enter the full text enclosed in quotation marks:

COUNTIF(range, "text")

To count cells with partial match, place the text between two asterisks, which represent any number of characters before and after the text:

COUNTIF(range, "*text*")

For example, to find how many cells in the range A2:A7 contain exactly the word "bananas", use this formula:

=COUNTIF(A2:A7, "bananas")

To count all cells that contain "bananas" as part of their contents in any position, use this one:

=COUNTIF(A2:A7, "*bananas*")

To make the formula more user-friendly, you can place the criteria in a predefined cell, say D2, and put the cell reference in the second argument:

=COUNTIF(A2:A7, D2)

Depending on the input in D2, the formula can match the sample text fully or partially:

  • For full match, type the whole word or phrase as it appears in the source table, e.g. Bananas.
  • For partial match, type the sample text surrounded by the wildcard characters, like *Bananas*.

As the formula is case-insensitive, you may not bother about the letter case, meaning that *bananas* will do as well.
Formulas to count cells that contain certain text – exact and partial match

Alternatively, to count cells with partial match, concatenate the cell reference and wildcard characters like:

=COUNTIF(A2:A7, "*"&D2&"*")
Formula to count cells with certain text in Excel

For more information, please see How to count cells with specific text in Excel.

How to count filtered cells with text in Excel

When using Excel filter to display only the data relevant at a given moment, you may sometimes need to count visible cells with text. Regrettably, there is no one-click solution for this task, but the below example will comfortably walk you through the steps.

Supposing, you have a table like shown in the image below. Some entries were pulled from a larger database using formulas, and various errors occurred along the way. You are looking to find the total number of items in column A. With all the rows visible, the COUNTIF formula that we've used for counting cells with text works a treat:

=COUNTIF(A2:A10, "*")

And now, you narrow down the list by some criteria, say filter out the items with quantity greater than 10. The question is – how many items remained?
Filtered cells with text that need to be counted

To count filtered cells with text, this is what you need to do:

  1. In your source table, make all the rows visible. For this, clear all filters and unhide hidden rows.
  2. Add a helper column with the SUBTOTAL formula that indicates if a row is filtered or not.
    To handle filtered cells, use 3 for the function_num argument:

    =SUBTOTAL(3, A2)

    To identify all hidden cells, filtered out and hidden manually, put 103 in function_num:

    =SUBTOTAL(103, A2)

    In this example, we want to count only visible cells with text regardless of how other cells were hidden, so we enter the second formula in A2 and copy it down to A10.

    For visible cells, the formula returns 1. As soon as you filter out or manually hide some rows, the formula will return 0 for them. (You won't see those zeros because they are returned for hidden rows. To make sure it works this way, just copy the contents of a hidden cell with the Subtotal formula to any visible say, say =D2, assuming row 2 is hidden.)
    Identifying visible cells

  3. Use the COUNTIFS function with two different criteria_range/criteria pairs to count visible cells with text:
    • Criteria1 - searches for cells with any text ("*") in the range A2:A10.
    • Criteria2 - searches for 1 in the range D2:D10 to detect visible cells.

    =COUNTIFS(A2:A10, "*", D2:D10, 1)

Now, you can filter the data the way you want, and the formula will tell you how many filtered cells in column A contain text (3 in our case):
Excel formula to count filtered cells with text

If you'd rather not insert an additional column in your worksheet, then you will need a longer formula to accomplish the task. Just choose the one you like better:

=SUMPRODUCT(SUBTOTAL(103, INDIRECT("A"&ROW(A2:A10))), --(ISTEXT(A2:A10)))

=SUMPRODUCT(SUBTOTAL(103, OFFSET(A2:A10, ROW(A2:A10) - MIN(ROW(A2:A10)),,1)), -- (ISTEXT(A2:A10)))

The multiplication operator will work as well:

=SUMPRODUCT(SUBTOTAL(103, INDIRECT("A"&ROW(A2:A10))) * (ISTEXT(A2:A10)))

=SUMPRODUCT(SUBTOTAL(103, OFFSET(A2:A10, ROW(A2:A10)-MIN(ROW(A2:A10)),,1)) * (ISTEXT(A2:A10)))

Which formula to use is a matter of your personal preference - the result will be the same in any case:
Formula to count visible cells with text

How these formulas work

The first formula employs the INDIRECT function to "feed" the individual references of all cells in the specified range to SUBTOTAL. The second formula uses a combination of the OFFSET, ROW and MIN functions for the same purpose.

The SUBTOTAL function returns an array of 1's and 0's where ones represent visible cells and zeros match hidden cells (like the helper column above).

The ISTEXT function checks each cell in A2:A10 and returns TRUE if a cell contains text, FALSE otherwise. The double unary operator (--) coerces the TRUE and FALSE values into 1's and 0's. At this point, the formula looks as follows:

=SUMPRODUCT({0;1;1;1;0;1;1;0;0}, {1;1;1;0;1;1;0;1;1})

The SUMPRODUCT function first multiplies the elements of both arrays in the same positions and then sums the resulting array.

As multiplying by zero gives zero, only the cells represented by 1 in both arrays have 1 in the final array.

=SUMPRODUCT({0;1;1;0;0;1;0;0;0})

And the number of 1's in the above array is the number of visible cells that contain text.

That's how to how to count cells with text in Excel. I thank you for reading and hope to see you on our blog next week!

Available downloads

Excel formulas to count cells with text

100 comments

  1. Hello
    Im create leave tracker where contain as below

    DAY Month Dtae EMple EMP2 EMP EMP4
    Mon Jul 7/1/2024 L WFH WFH WFH
    Tue Jul 7/2/2024 WFO WFO WFO WFO
    Wed Jul 7/3/2024 WFO WFO WFO WFO
    Thu Jul 7/4/2024 WFH WFH L WFH
    Fri Jul 7/5/2024 WFH WFH WFH WFH
    Sat Jul 7/6/2024 WO WO WO WO
    Sun Jul 7/7/2024 WO WO WO WO
    Mon Jul 7/8/2024 WFH WFH WFH L
    Tue Jul 7/9/2024 WFO WFO WFO WFO
    Wed Jul 7/10/2024 WFO WFO WFO WFO
    Thu Jul 7/11/2024 WFH WFH WFH WFH
    Fri Jul 7/12/2024 WFH L WFH WFH
    Sat Jul 7/13/2024 WO WO L WO
    Sun Jul 7/14/2024 WO WO WO WO
    Mon Jul 7/15/2024 WFH WFH WFH WFH
    Tue Jul 7/16/2024 WFO WFO WFO WFO
    Wed Jul 7/17/2024 WFO WFO WFO WFO
    Thu Jul 7/18/2024 WFH WFH WFH WFH
    Fri Jul 7/19/2024 WFH WFH WFH WFH
    Sat Jul 7/20/2024 WO WO WO WO
    Sun Jul 7/21/2024 WO WO WO WO
    Mon Jul 7/22/2024 WFH WFH WFH WFH

    i want to count associate number days L , WO WFH , WFO by the month i have tracker for the year and i need a report where i can use the filter and view by month

    Aug
    Count EMP 1emp 2 a Emp3 emp 4
    Leave 1 1 2 1
    Holiday 0 0 0 0
    Work from Home 14 14 14 14
    Office 10 10 10 10
    Week OFF 86 86 85 86

  2. I have 2 columns A and B. In A I have many types of text "Apple", "Banana", "Orange", "Pineapple", "Strawberries. In column B I'm adding the amount for each type of text. In column C I need a formula where when I type only Apple or Banana (Orange, Pineapple, Strawberries - are not important) their amount to be shown in column C.

    Thank You

  3. Can you please help me to:(My data range contains numbers, text and also numbers with formulas and text with formulas
    Find out the count of numbers without formula in the data range
    Find out the count of text without formula in the data range

    • Hi! Use the NOT and ISFORMULA functions to identify cells that do not contain formulas. Use the ISNUMBER function to define cells with numbers. Use NOT and ISNUMBER function to identify cells with text. Use the SUMPRODUCT function to find the number of cells you need. For example:

      =SUMPRODUCT((NOT(ISFORMULA(A1:A5))) * ISNUMBER(A1:A5))

      • Excellent Sir, My problem resolved

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)