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. I have a table in Excel with thousands of rows. If I apply certain filters to any column, the quantity is reduced specifically to the quantity that the filter applies to it. I want to know, how can I make the program count the number of rows and show the result every time I change the filter?

    • Hello! To count only the visible cells in an Excel range and ignore hidden ones (such as those filtered out), you can use different methods:
      1. Using the SUBTOTAL Function:
      Enter the formula =SUBTOTAL(3, A1:A100) (where range represents the area you want to count, excluding hidden rows or columns).
      2. Using the AGGREGATE Function:
      Enter the formula =AGGREGATE(3,5,A1:A100) (where range is the area you want to count, ignoring hidden cells).
      Other Excel functions cannot ignore hidden cells.

  2. I want to count (and display) the number of cells in a column that contain text. I am using this formula in cell D24: =COUNTIF(D4:D23,"*")
    The sum does not appear in cell D24, but the formula does. What am I doing wrong?

  3. Hi
    I am trying to work on 4 columns.

    Column D - Year groups ie Year 10, Year 11, Year 12
    Column J - 1st colour ie red, green, blue
    Column K - 2nd colour ie red, green, blue
    Column L - 3rd colour ie red, green, blue

    The count I am trying to do is this: I only want to include Year 10. I want to count every time red appears in J, K or L for Year 10 (Year 10 is 17 lines and red only appears in J, K or L, never in all three, for each line). Some cells in J, K, L are blank. Cells in D are always Year X.
    I am trying to do the formula on a different sheet to the data.

    I have tried this: COUNTIFS ('sheetx'!D:D,"Year 10", J:J, "red")+COUNTIFS('sheetx'!D:D,"Year 10",K:K,"red")+COUNTIFS('sheetx'!D:D,"Year10",L:L,"red")

    It doesn't seem to work. Please help.

  4. My example data:
    4B
    4A*
    4A*
    4A
    3A* 1B
    3A* 1B
    3A* 1b
    3A* 1A
    3A* 1a
    3A* 1A
    3A* 1A
    3A 1D
    3A 1d
    2C 1D 1d
    2C 1D

    I need to count this data. 4A* should have 2 and 4A should have 1, but they will count and combine all become 3. I also have 3A 1D and 3A 1d which each should count as 1. Can you help me to count the exact data?

  5. Thank you so much for he countifs explaination it really helped me out for a work project.

  6. =COUNTIF(E6:AV6, ">0")

    WORKS TO COUNT THE CELLS WITH NUMBERS ONLY

  7. As i am doing payment follow with customers.
    I have made format for 4 times payment follow up with customers.
    For example:
    Column A - Date
    Column B - Paid/ not paid
    As per 4 times follow up schedule it repeats upto column H
    Now, i want to count total number of paid in specific dates.

    Help me with formula to do so.

    Will be thankful.

    Regards,
    Nimesh Palikhel

  8. Hello
    I am trying to use same formula to count the specific text , if put number 1 ,2 ,3 in cell its shows the correct result . but when i am putting time i.e. 5:45 to 1:30 its show incorrect result . Kindly help.

    =SUMIF($D$6:$D$14,"OPEN",F6:F14) + SUMIF(F6:F14,"D/O",F6:F14)

  9. Hi,

    im using this formula to calculate the amount of quotes i do with different reasons.

    =COUNTIF('New Business'!G1:G129,"Quoted")+COUNTIF('New Business'!G1:G129,"Quoted NG")+COUNTIF('New Business'!G1:G129,"Sold")

    how do i get it to only count them for a certain month i.e. april?

  10. Thank you, thank you, thank you. I had a column of cells with names, like an attendance register, with several blank cells. I wanted to count the number of cells with names but not the empty cells. Unfortunately Excel counts spaces as text, so using COUNTA wouldn't work.
    The formula suggested to not count cells with spaces, =COUNTIFS(A2:A7,"*?*",A2:A7,""""), worked. Then, the explanation on how the "*?*" operator worked made me wonder if I could use that with a COUNTIF statement and that seemed work also. =COUNTIF(A2:A7,"*?*")

  11. I want to Count Column A item according to Column B ... please help me how to count column A item into column B

  12. Hi
    I have a table with sales data for the full year, I want to Count how many Orders are Won or Lost per salesperson each month so it can auto-populate pie chart data, I "Think" I need a count if but never used the formula before. Happy to share my table and explain further if anybody can help but basically:
    Column A = Salesperson
    Column B = Date
    Column C = Feedback (Ordered or Lost)

    I want to auto-populate another table that shows how many orders a certain salesperson has won in January then February etc...

  13. Hello,

    We have a large spreadsheet which tracks the hiring process for a large organization with multiple Bureaus and Departments.

    I am trying to determine the formula for the following scenarios so I can create a "dashboard" summary on a different worksheet:

    I need to determine the number of Job Titles per Bureau. The info resides in 2 columns. Column D lists the Bureau Name (there are 8 Bureaus listed. An example of a Bureau name is BAM) and Column G lists the Job Titles (currently there are 123 different titles in the data). I need to determine the unique job titles per Bureau.

    I also need to do the same thing for Departments. There are 24 different departments and they are listed in Column E.

    Please help! I've tried different combinations of COUNTIFS, COUNTA, IFERROR but I haven't landed on the right solution.

    Thanks in advance.

    I also need to determine the number of Job Titles per Bureau

      • Hi,

        I tried that already and it didn't work. I need to count the unique Job Titles in Column G. As stated above, there are currently 123 unique job titles in a column of about 400 entries. The example in the link outlines looking for specific information (Basketball and <18) so the formula in the link doesn't work.

        Please help...

        • Nevermind! I figured it out.

          The winning formula was =IFERROR(ROWS(UNIQUE(FILTER('Hiring Process'!G4:G500,'Hiring Process'!D4:D500=D2))), 0)

        • Hi!
          Did you read the article I recommended?
          You wrote: "I need to determine the unique job titles per Bureau". The formula, from paragraph 5, is suitable for this case. Now you write something else: "I need to count the unique Job Titles in Column G". The formula for this is in the first paragraph.

          • Hi,

            I used this formula: =IFERROR(ROWS(UNIQUE(FILTER('Hiring Process'!G4:G500,'Hiring Process'!D4:D500=D2))), 0) but the result is 1 higher than what it should be. I cannot figure out what should change. Can someone help? Maybe someone can jump on a Zoom/Teams call?

          • So after using the formula above, we aren't getting accurate results. The results are 1 higher than what they should be and I'm not sure why. Can someone help?

            • Hi!
              Without seeing your data it is difficult to give you any advice.
              I can assume that one of the values in your data has extra space or some other character that you don't see. Check it out.

          • We think we've figured out the problem, but don't know exactly how to solve it in the formula.

            We believe the formula is counting all blank cells as one unique value, hence why it the results are higher. We found the "" solution, but do not know where to put it within the formula we are using. We've tried a number of places and nothing is coming up with the right answer.

            How can we filter out blanks while also filtering on multiple criteria? Any advice or assistance would be appreciated!

            THANK YOU!

  14. Respected Sir,
    What is the formula for counting text of different cell which is not in a range. for Example how to calculate text of A1+C1+F1

  15. Hi, Thank you so much for this!!

    One question though. I have a row of cells that shows this [Logo: Diamond, Size: Medium Devlievery: Pick up)

    I am using the formula you explained as such:

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

    to calculate the number of times "Diamond logo appears in the row. But I also want to have a cell return me the total amount of "Medium size t shirts with Diamond logo"

    I tried this:

    =COUNTIF(A2:A7, "*Diamond*" + "*Medium*")

    Did not work obviously. However, what formula should I use to do so?

    Thanks in advance!

  16. Hi,

    how do I convert the below to be able to use using a filter:
    COUNTIFS(D:D, "buy", M:M, ">0")

    I will be filtering from month to month in yearly data to grab the above.

    Thanks all!

  17. Hello,
    I have a spreadsheet that has a list of categories using roman numerals I to VI. The spreadsheet has over 6000 rows (each row is a assigned to a hospital room) and I filter it for most applications. I want to be able to count specific categories after filtered. Once it is filter and I can count manually 20 Cat I's and 13 Cat VI's but my current formula counts all filtered and unfiltered. What formula would count these characters separately after being filtered and give a total of each cell in a column that has these specific characters? at the bottom of the page. The bottom of the column would look like this and not count unfiltered data.
    Cat I = 22
    Cat II = 23
    Cat III= 15
    Cat IV= 32
    Etc.... I hope this makes since.
    V/r
    Ron Lambert

    • Hello!
      Based on your description, it is hard to completely understand your task. However, I’ll try to guess and offer you the following formula:

      =COUNTIF(A2:A1000, "*Cat I*")

      If this is not what you wanted, please describe the problem in more detail.

  18. Hi,
    Good day!

    Please help me to correct this formula for monthly timesheet summary:

    If(‘May2021’!C:C,”=Tony”, countif(‘May2021’!D:Z,”=Present”)

    Thank you so much

  19. HI,

    Good day!

    can you help me if this is possible to do in excel, I want to count the number of cells containing the specific value that is within a specific row or column that is in between a specific value in a cell.

    i.e. COUNT THE CELLS IN A ROW BETWEEN "JAN"

    A B C D E F G H I
    1 TOTAL COUNT
    2 JAN FEB MAR OCT SEPT MAR JAN AUG 5
    3 FEB JAN DEC FEB JAN APR MAR OCT 2
    4

    I.E. COUNT THE NUMBER OF CELLS HAVING "P" BETWEEN "O".

    A B C D E F G H I
    1 TOTAL COUNT
    2 O P P P P P O P 5
    3 P O P P O P P P 2
    4

  20. I have a spreadsheet that has a column for each month (12 columns) and a row for each day (31 rows), I have put in each column and row a letter to track type of days off, I want to total the types of days off on a separate spreadsheet. Is there a formula that will do this for me?

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 :)