How to Count Cells that Contain Text in Excel

This post will guide you how to count the number of cells that text only within a range of cells using a formula in Excel 2013/2016 or Excel office 365. How do I count the number of cells with text values(not errors, not numbers, not blanks) using a simple formula in Excel. When you analyze a large list of data with texts and numbers, you may also want to know that how many cells that contain text values. The below steps will show you how to do it in a simple way.

1. Count Number of Cells that Contain Text

You can use the COUNTIF function to count cells that contain text (not errors, not numbers, not blanks). And you can use the COUNTIF function with a wildcard that matches any number of characters in cells.

The below is a generic formula to count the number of cells containing text:

=COUNTIF(range,*)

Assuming that you have a list of data in range B1:B6 and you want to count the number of cells with text values only. And you can add the the asterisk(*) as a wildcard in the second argument as its criteria and you will get the below formula:

=COUNTIF(B1:B6,”*”)
count cells that contain text1

LET’S SEE THAT HOW THIS FORMULA WORKS:

The COUNTIF function can be used to count the number of cells that match a single condition or criteria. And in this case, you need to provide a criteria as “*”, which is evaluated as “values that containing any text characters”. Then the total count of all cells in the range B1:B6 that meet the above criteria is returned.

If you want to count cells with text characters in a range of cells, but exclude cells with only a space character, and you can use the COUNTIFS function to supply more specific criteria to achieve the result. Using the below generic formula:

=COUNTIFS(B1:B6,"*",B1:B6,"<> ")

2. Count Cells that Contain Text using VBA Code

Now, moving on to the second method, we’ll explore using VBA code to count cells containing text. This method provides more flexibility and customization options for advanced counting tasks.

Press ‘Alt + F11’ to open the Visual Basic for Applications (VBA) editor.

Right-click on any item in the project explorer (on the left), hover over “Insert” and select “Module” to add a new module.

In the newly created module, copy and paste the following VBA code:

Function CountTextCells(rng As Range) As Long
    Dim cell As Range
    Dim count As Long
    
    For Each cell In rng
        If Not IsError(cell.Value) And Not IsNumeric(cell.Value) And cell.Value <> "" Then
            count = count + 1
        End If
    Next cell
    
    CountTextCells = count
End Function

Close the VBA editor and return to your Excel workbook.

In a cell where you want the result, enter the formula:

= CountTextCells(B1:B6)

Replace “B1:B6” with the range where you want to count cells containing text.

After entering the formula, press Enter to execute it.

The VBA function will count the number of cells containing text in the specified range.

3. Video: Count Cells that Contain Text

This Excel video tutorial on counting cells that contain text. In this video, we’ll explore two methods: using a formula with the COUNTIF function and implementing VBA code.

4. Related Functions

  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria. This function can be used to count the different kinds of cells with number, date, text values, blank, non-blanks, or containing specific characters. etc. = COUNTIF (range, criteria) …
  • Excel COUNTIFS function
    The Excel COUNTIFS function returns the count of cells in a range that meet one or more criteria. The syntax of the COUNTIFS function is as below:= COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)…