Excel formulas to count cells with text: any, specific or filtered cells (2024)

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 countedWhat 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 formulas to count cells with text: any, specific or filtered cells (1)

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, "<> ")
Excel formulas to count cells with text: any, specific or filtered cells (2)

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:
Excel formulas to count cells with text: any, specific or filtered cells (3)

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.
Excel formulas to count cells with text: any, specific or filtered cells (4)

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

=COUNTIF(A2:A7, "*"&D2&"*")
Excel formulas to count cells with text: any, specific or filtered cells (5)

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?
Excel formulas to count cells with text: any, specific or filtered cells (6)

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.)
    Excel formulas to count cells with text: any, specific or filtered cells (7)

  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 formulas to count cells with text: any, specific or filtered cells (8)

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:
Excel formulas to count cells with text: any, specific or filtered cells (9)

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

Excel formulas to count cells with text: any, specific or filtered cells (2024)

FAQs

How do I count specific answers in Excel? ›

Use the COUNTIF function to count how many times a particular value appears in a range of cells.

How do I count by filtered values in Excel? ›

Count Rows in Filtered List With AGGREGATE
  1. Apply an AutoFilter to the table. ...
  2. Filter at least one of the columns in the table. ...
  3. Select the cell in which you want to see the total -- cell B1 in this example.
  4. To start the formula, type: =AGGREGATE(
  5. In the list of function numbers, double-click on 3-COUNTA, then type a comma.
5 days ago

How to use Countif with filtered data? ›

Countif filtered data with criteria by Excel functions

In a blank cell enter the formula =SUMPRODUCT(SUBTOTAL(3,OFFSET(B2:B18,ROW(B2:B18)-MIN(ROW(B2:B18)),,1)),ISNUMBER(SEARCH("Pear",B2:B18))+0), and press the Enter key. Formula is too complicated to remember?

How do you number only filtered cells? ›

Here are the steps:
  1. Filter your data.
  2. Select the cells you want to add the numbering to.
  3. Press F5.
  4. Select Special.
  5. Choose "Visible Cells Only" and press OK.
  6. Now in the top row of your filtered data (just below the header) enter the following code: ...
  7. Hold Ctrl and press enter.

How do you count excluding hidden cells? ›

Count ignore hidden cells and rows with excel functions

Select a blank cell you will place the counting result into, type the formula =SUBTOTAL(102,C2:C22) (C2:C22 is the range where you want to count ignoring manually hidden cells and rows) into it, and press the Enter key.

How do I count how many cells contain a certain text? ›

To count all the text values in the given Excel sheet, you can use the COUNTIF function along with a wildcard character. This function with a wildcard counts all the text values in a given range. To count the cells with text in Excel, choose a destination cell and enter the formula =COUNTIF(range,criteria).

How do I use Countif with two conditions? ›

How to Countif Multiple Criteria?
  1. Step 1: document the criteria or conditions you wish to test for.
  2. Step 2: type “=countifs(“ and select the range you want to test the first criteria on.
  3. Step 3: input the test for the criteria.
  4. Step 4: select the second range you want to test (it can be the same range again, or a new one)
24 Nov 2022

How do I count cells that contain certain text? ›

Count Cells that Contain a Particular String Anywhere within the Cell
  1. Type =COUNTIF( in the cell where you want to see the count.
  2. Select the range of cells to count.
  3. Type a comma to go to the next argument and enter the text for which you want to search. ...
  4. Hit enter and you have the result:

What is the formula for To sum for filtered cells in Excel? ›

1. In a blank cell, C13 for example, enter this formula: =Subtotal(109,C2:C12) (109 indicates when you sum the numbers, the hidden values will be ignored; C2:C12 is the range you will sum ignoring filtered rows.), and press the Enter key.

How do you count non blank cells in a filtered list? ›

Please enter this formula: =SUBTOTAL(102,B2:B20) into a blank cell, then press Enter key, the number of non-blank cells in the filtered list has been displayed at once, see screenshot: Note: In the above formula, B2:B20 is the column that you want to count the non-blank cells from.

Can you Vlookup only filtered data? ›

The VLOOKUP function can help you to find and return the first matching value by default whether it is a normal range or filtered list.

How do you count cells regardless of content? ›

On the Formulas tab, click More Functions, point to Statistical, and then click one of the following functions:
  1. COUNTA: To count cells that are not empty.
  2. COUNT: To count cells that contain numbers.
  3. COUNTBLANK: To count cells that are blank.
  4. COUNTIF: To count cells that meets a specified criteria.

How do you count cells that meet a criteria? ›

Use COUNTIF, one of the statistical functions, to count the number of cells that meet a criterion; for example, to count the number of times a particular city appears in a customer list. In its simplest form, COUNTIF says: =COUNTIF(Where do you want to look?, What do you want to look for?)

Can you use Countif for 3 criteria? ›

Excel has many functions where a user needs to specify a single or multiple criteria to get the result. For example, if you want to count cells based on multiple criteria, you can use the COUNTIF or COUNTIFS functions in Excel.

Can you do a Countif based on conditional formatting? ›

IF you want to count based on CF rules, you can use the same rule you have used to apply conditional formatting and count the total values. For example, if you use CF to highlight cells that contain “Yes”, then use a COUNTIF function to count all these cells.

What is difference between Countif and Countifs? ›

The difference between COUNTIF and COUNTIFS is that COUNTIF is designed for counting cells with a single condition in one range, whereas COUNTIFS can evaluate different criteria in the same or different ranges.

Can I use a count function for text? ›

Count Text Cells in Excel

Text Cells can be easily found in Excel using COUNTIF or COUNTIFS functions. The COUNTIF function searches text cells based on specific criteria and in the defined range. As in the example below, the defined range is table Name list, and text criteria is defined using wildcard “*”.

How do you sum cells contain specific text in Excel? ›

Sum if cell contains text

If you are looking for an Excel formula to find cells containing specific text and sum the corresponding values in another column, use the SUMIF function. Where A2:A10 are the text values to check and B2:B10 are the numbers to sum. To sum with multiple criteria, use the SUMIFS function.

How do you use Countifs with or? ›

Count cells with OR conditions by using SUM and COUNTIFS functions. In Excel, to count with multiple OR conditions, you can use the SUM and COUNTIFS functions with an array constant, the generic syntax is: =SUM(COUNTIF(range, {criterion1, criterion2, criterion3, …}))

Can you do a subtotal Countif? ›

The SUBTOTAL function can easily generate sums and counts for visible rows. However, SUBTOTAL is not able to apply criteria like the COUNTIFS function without help. Conversely, COUNTIFS can easily apply criteria, but is not able to distinguish between rows that are visible and rows that are hidden.

How do you dynamically count rows in Excel? ›

Use a Dynamic Range With the COUNTIF - INDIRECT Formula

Using INDIRECT as the argument for COUNTIF creates a dynamic range of cell references that can be counted by the function if the cell values meet a criteria. It does this by turning text data, sometimes referred to as a text string, into a cell reference.

What is the difference between count and Counta? ›

The COUNTA function does not count empty cells. If you do not need to count logical values, text, or error values (in other words, if you want to count only cells that contain numbers), use the COUNT function.

How do I count selected cells in Excel with text? ›

On the Formulas tab, click More Functions, point to Statistical, and then click one of the following functions:
  1. COUNTA: To count cells that are not empty.
  2. COUNT: To count cells that contain numbers.
  3. COUNTBLANK: To count cells that are blank.
  4. COUNTIF: To count cells that meets a specified criteria.

How do you count a cell if it contains any text? ›

“Double-tap” on an “empty cell” in the spreadsheet to enter the “COUNTIF” formula, or you can “long-press” an “empty cell” then tap “Edit” from the pop-up menu. In the empty cell, type in the following: “ =COUNTIF (range, criteria) .” This formula counts the number of cells containing text inside your cell range.

How do I count if multiple cells contain text? ›

You can use the COUNTIFS function in Excel to count cells in a single range with a single condition as well as in multiple ranges with multiple conditions. If the latter, only those cells that meet all of the specified conditions are counted.

Top Articles
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 6290

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.