Count in excel for text

Microsoft Word allows you count text, but what about Excel? If you need a count of your text in Excel, you can get this by using the COUNTIF function and then a combination of other functions depending on your desired result. 

How to count text in Excel

If you want to learn how to count text in Excel, you need to use function COUNTIF with the criteria defined using wildcard *, with the formula: =COUNTIF(range;"*"). Range is defined cell range where you want to count the text in Excel and wildcard * is criteria for all text occurrences in the defined range.

Some interesting and very useful examples will be covered in this tutorial with the main focus on the COUNTIF function and different usages of this function in text counting. Limitations of COUNTIF function have been covered in this tutorial with an additional explanation of other functions such as SUMPRODUCT/ISNUMBER/FIND functions combination. After this tutorial, you will be able to count text cells in excel, count specific text cells, case sensitive text cells and text cells with multiple criteria defined – which is a very good base for further creative Excel problem-solving.                

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 “*”. The formula result is 5, all text cells have been counted. Note that number formatted as text in cell B10 is also counted, but Booleans (TRUE /FALSE) and error (#N/A) are not recognized as text.

The formula for counting text cells:

=COUNTIF(range;"*")

For counting non-text cells, the formula should be a little bit changed in criteria part:

=COUNTIF(range;"<>*")

If there are several criteria for counting cells, then COUNTIFS function should be used. For example, if we want to count the number of employees from Texas with project number greater than 20, then the function will look like:

=COUNTIFS(C3:C6;"Texas";D3:D6;">20").

In criteria range in column State, a specific text criteria is defined under quotations “Texas”. The second criteria is numeric, criteria range is column Number of projects, and criteria is numeric value greater than 20, also under quotations “>20”. If we were looking for exact value, the formula would look like:

=COUNTIFS(C3:C6;"Texas";D3:D6;20)

Count Specific Text in Cells

For counting specific text under cells range, COUNTIF function is suitable with the formula:

=COUNTIF(range;"*text*")

=COUNTIF(B3:B9;"*Mike*")

The first part of the formula is range and second is text criteria, in our example  “*Mike*”. If wildcard * has not been used before and after criteria text, formula result would have been 1 (Formula would find cells only with word Mike).  Wildcard * before and after criteria text, means that all cells that contain criteria characters will be taken into account. As in another example below with text criteria Sun, three cells were found (sun, Sunny, sun is shining)

=COUNTIF(B3:B10;"*Sun*")

Note: The COUNTIF function is not case sensitive, an alternative function for case sensitive text searches is SUMPRODUCT/FIND function combination.

Count Case Sensitive Specific Text

For a case-sensitive text count, a combination of three formulas should be used: SUMPRODUCT, ISNUMBER and FIND. Let’s look in the example below. If we want to count cells that contain text Sun, case sensitive, COUNTIF function would not be the appropriate solution, instead of this function combination of three functions mentioned above has to be used.

=SUMPRODUCT(--ISNUMBER(FIND("Sun";B3:B10)))

We should go through a separate function explanation in order to understand functions combination. FIND function, searches specific text in the defined cell, and returns the number of the starting position of the text used as criteria. This explanation is relevant, if the searching range is just one cell. If we want to use FIND function in a range of the cells, then the combination with SUMPRODUCT function is necessary.  

Without ISNUMBER, function combination of FIND and SUMPRODUCT functions would return an error. ISNUMBER function is necessary because whenever FIND function does not match defined criteria, the output will be an error, as in print screen below of the evaluated formula.

In order to change error values with Boolean TRUE/FALSE statement, ISNUMERIC formula should be used (defining numeric values as TRUE, and non-numeric as FALSE, as in print screen below).

You might be wondering what character in SUMPRODUCT function stands for. It converts Boolean values TRUE/FALSE in numeric values 1/0, enabling SUMPRODUCT function to deal with numeric operations (without character — in SUMPRODUCT function, the final result would be 0).

Remember, if you want to count specific text cells that are not case sensitive, COUNTIF function is suitable. For all case sensitive searches combination of SUMPRODUCT/ISNUMBER/FIND functions is appropriate.

Count Text Cells with Multiple Criteria

If you want to count cells with Multiple criteria, with all criteria acceptable, there is an interesting way of solving that problem, a combination of SUMPRODUCT/ISNUMBER/FIND functions. Please take a look in the example below. We should count all cells that contain either Mike or $. Tricky part could be the cells that contain both Mike and $.

=SUMPRODUCT(--(ISNUMBER(FIND("Mike";B3:B11))+ISNUMBER(FIND("$";B3:B11))>0))

Formula just looks complex, in order to be easier for understanding, I will divide it into several steps. Also, knowledge from the previous tutorial point will be necessary for further work, since the combination of FIND, ISNUMBER, and SUMPRODUCT functions have been explained.

In the first part of the function, we loop through the table and find cells that contain Mike:

=ISNUMBER(FIND("Mike";B3:B11))

The output of this part of the function will be an array with values  {1;0;0;0;1;0;0;0;1}, number 1, where criteria have been met, and 0, where has not.

In the second part of the function, looping criteria is $, counting cells containing this value:

=ISNUMBER(FIND("$";B3:B11))

The output of this part of the function will be an array with values  {1;0;0;1;1;0;0;0;1}, number 1, where criteria have been met, and 0, where has not.

Next step is to sum these two arrays, since cell should be counted if any of conditions is fulfilled:

=ISNUMBER(FIND("Mike";B3:B11))+ISNUMBER(FIND("$";B3:B11))

The output of this step is {2;0;0;1;2;0;0;0;2}, the number  greater than 0 means that one of the condition has been met (2 – both conditions, 1 – one condition)

Without function part >0, the final function would double count cells that met both conditions and the final result would be 7 (sum of all array numbers). In order to avoid it, in the formula should be added >0:

=ISNUMBER(FIND("Mike";B3:B11))+ISNUMBER(FIND("$";B3:B11))>0

The output of this step is array {1;0;0;1;1;0;0;0;1}, the previous array has been checked and only values greater than 0 are TRUE (in an array have value 1), and others are FALSE (in an array have value 0).

Final output of the formula is the sum of the final array values, 4.

Looks very confusing, but after several usages, you will become familiar with this functions.

At the end, we will cover one more multiple criteria text count function, already mentioned in the tutorial, COUNTIFS function. In order to distinguish the usage of functions mentioned above and COUNTIFS function, two words are enough OR/AND. If you want to count text cells with multiple criteria but all conditions have to be met at the same time, then COUNTIFS function is appropriate. If at least one condition should be met, then the combination of function explained above is suitable.

Look at the example below, the number of cells that contain both Mike and $ is easily calculated with COUNTIFS function:

=COUNTIFS(range1;"*text1*";range2;"*text2*")

=COUNTIFS(B3:B11;"*Mike*";B3:B11;"*$*")

In the defined range, function counts only cells where both conditions have been met. The final result is 3.

Still need some help with Excel formatting or have other questions about Excel? Connect with a live Excel expert here for some 1 on 1 help. Your first session is always free. 

In this example, the goal is to count cells in a range that contain text values. This could be hardcoded text like «apple» or «red», numbers entered as text, or formulas that return text values. Empty cells, and cells that contain numeric values or errors should not be included in the count. This problem can be solved with the COUNTIF function or the SUMPRODUCT function. Both approaches are explained below. For convenience, data is the named range B5:B15.

COUNTIF function

The simplest way to solve this problem is with the COUNTIF function and the asterisk (*) wildcard. The asterisk (*) matches zero or more characters of any kind. For example, to count cells in a range that begin with «a», you can use COUNTIF like this:

=COUNTIF(range,"a*") // begins with "a"

In this example however we don’t want to match any specific text value. We want to match all text values. To do this, we provide the asterisk (*) by itself for criteria. The formula in H5 is:

=COUNTIF(data,"*") // any text value

The result is 4, because there are four cells in data (B5:B15) that contain text values.

To reverse the operation of the formula and count all cells that do not contain text, add the not equal to (<>) logical operator like this:

=COUNTIF(data,"<>*") // non-text values

This is the formula used in cell H6. The result is 7, since there are seven cells in data (B5:B15) that do not contain text values.

COUNTIFS function

To apply more specific criteria, you can switch to the COUNTIFs function, which supports multiple conditions. For example, to count cells with text, but exclude cells that contain only a space character, you can use a formula like this:

=COUNTIFS(range,"*",range,"<> ")

This formula will count cells that contain any text value except a single space (» «).

SUMPRODUCT function

Another way to solve this problem is to use the SUMPRODUCT function with the ISTEXT function.  SUMPRODUCT makes it easy to perform a logical test on a range, then count the results. The test is performed with the ISTEXT function. True to its name, the ISTEXT function only returns TRUE when given a text value:

=ISTEXT("apple")// returns TRUE
=ISTEXT(70) // returns FALSE

To count cells with text values in the example shown, you can use a formula like this:

=SUMPRODUCT(--ISTEXT(data))

Working from the inside out, the logical test is based on the ISTEXT function:

ISTEXT(data)

Because data (B5:B15) contains 11 values, ISTEXT returns 11 results in an array like this:

{TRUE;TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE}

In this array, the TRUE values correspond to cells that contain text values, and the FALSE values represent cells that do not contain text. To convert the TRUE and FALSE values to 1s and 0s, we use a double negative (—):

--{TRUE;TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE}

The resulting array inside the SUMPRODUCT function looks like this:

=SUMPRODUCT({1;1;1;0;0;1;0;0;0;0;0}) // returns 4

With a single array to process, SUMPRODUCT sums the array and returns 4 as the result.

To reverse the formula and count all cells that do not contain text, you can nest the ISTEXT function inside the NOT function like this:

=SUMPRODUCT(--NOT(ISTEXT(data)))

The NOT function reverses the results from ISTEXT. The double negative (—) converts the array to numbers, and the array inside SUMPRODUCT looks like this:

=SUMPRODUCT({0;0;0;1;1;0;1;1;1;1;1}) // returns 7

The result is 7, since there are seven cells in data (B5:B15) that do not contain text values.

Note: the SUMPRODUCT formulas above may seem complex, but using Boolean operations in array formulas is powerful and flexible. It is also an important skill in modern functions like FILTER and XLOOKUP, which often use this technique to select the right data. The syntax used by COUNTIF on the other hand is unique to a group of eight functions and is therefore not as useful or portable.

Watch Video – How to Count Cells that Contain Text Strings

Counting is one of the most common tasks people do in Excel. It’s one of the metric that is often used to summarize the data. For example, count sales done by Bob, or sales more than 500K or quantity of Product X sold.

Excel has a variety of count functions, and in most cases, these inbuilt Excel functions would suffice. Below are the count functions in Excel:

  • COUNT – To count the number of cells that have numbers in it.
  • COUNTA – To count the number of cells that are not empty.
  • COUNTBLANK – To count blank cell.
  • COUNTIF/COUNTIFS – To count cells when the specified criteria are met.

There may sometimes be situations where you need to create a combination of functions to get the counting done in Excel.

One such case is to count cells that contain text strings.

Count Cells that Contain Text in Excel

Text values can come in many forms. It could be:

  • Text String
    • Text Strings or Alphanumeric characters. Example – Trump Excel or Trump Excel 123.
  • Empty String
    • A cell that looks blank but contains =”” or ‘ (if you just type an apostrophe in a cell, it looks blank).
  • Logical Values
    • Example – TRUE and FALSE.
  • Special characters
    • Example – @, !, $ %.

Have a look at the data set shown below:

Count Cells that Contain Text in Excel Data Set

It has all the combinations of text, numbers, blank, special characters, and logical values.

To count cells that contain text values, we will use the wildcard characters:

  • Asterisk (*): An asterisk represents any number of characters in excel. For example, ex* could mean excel, excels, example, expert, etc.
  • Question Mark (?): A question mark represents one single character. For example, Tr?mp could mean Trump or Tramp.
  • Tilde (~): To identify wildcard characters in a string.
See Also: Examples of using Wildcard Characters in Excel.

Now let’s create formulas to count different combinations.

Count Cells that Contain Text in Excel (including Blanks)

Here is the formula:

=COUNTIF(A1:A11,”*”)

This formula uses COUNTIF function with a wildcard character in the criteria. Since asterisk (*) represents any number of characters, it counts all the cells that have text characters in it.

It even counts cells that have an empty string in it (an empty string can be a result of formula returning =”” or a cell that contains an apostrophe). While a cell with empty string looks blank, it is counted by this formula.

Logical Values are not counted.

Count Cells that Contain Text in Excel Text with blanks

Count Cells that Contain Text in Excel (excluding Blanks)

Here is the formula:

=COUNTIF(A1:A11,”?*”)

In this formula, the criteria argument is made up of a combination of two wildcard characters (question mark and asterisk). This means that there should, at least, be one character in the cell.

This formula does not count cells that contain an empty string (an apostrophe or =””). Since an empty string has no character in it, it fails the criteria and is not counted.

Logical Values are also not counted.

Count Cells that Contain Text in Excel Text without blanks

Count Cells that Contain Text (excluding Blanks, including Logical Values)

Here is the formula:

=COUNTIF(A1:A11,”?*”) + SUMPRODUCT(–(ISLOGICAL(A1:A11))

The first part of the formula uses a combination of wildcard characters (* and ?). This returns the number of cells that have at least one text character in it (counts text and special characters, but does not count cells with empty strings).

The second part of the formula checks for logical values. Excel ISLOGICAL function returns TRUE if there is a logical value and FALSE if there isn’t. A double negative sign ensures that TRUEs are converted into 1 and FALSEs into 0. Excel SUMPRODUCT function then simply returns the number of cells that have a logical value in it.

Count Cells that Contain Text in Excel Text with Logical Values

These above examples demonstrate how to use a combination of formulas and wildcard characters to count cells. In a similar fashion, you can also construct formulas to find the SUM or AVERAGE of a range of cells based on the data type in it.

You May Also Like the Following Excel Tutorials:

  • Count the Number of Words in a Text String.
  • Using Multiple Criteria in Excel COUNTIF and COUNTIFS Function.
  • How to Count Colored Cells in Excel.
  • Count Characters in a Cell (or Range of Cells) Using Formulas in Excel

Понравилась статья? Поделить с друзьями:
  • Count in excel but not duplicates
  • Count in between dates excel
  • Count if with and in excel
  • Count if true excel
  • Count if this and this excel