How to Count the Occurrences of a Character in a String in Excel – 4 Examples

The image below showcases the number of occurrences of characters in a string in some book names.

How to Count Occurrences of Character in String in Excel

 


Example 1 – Count the Occurrences of a Character in a String Considering Letter Cases

  • Choose a cell to display the character count.
  • Use the formula:

=LEN(B6)-LEN(SUBSTITUTE(B6,C6,""))

  • Replace B6 and C6 with the cell references containing your text and the specific character you want to count.
  • Press Enter and drag down the Fill Handle.Count Case-Sensitive Characters Combining LEN and SUBSTITUTE Functions

Formula Breakdown

The LEN function determines the number of characters in a string. The SUBSTITUTE function replaces specified characters with empty spaces. By subtracting the length of the modified string from the original, it returns the count of the characters you are looking for.

Finally, you will get the number of all the case-sensitive characters in the above image.


Example 2 – Count the Occurrences of a Character in a String Ignoring Letter Cases

  • Enter the following formula:

=LEN(B6)-LEN(SUBSTITUTE(UPPER(B6),UPPER(C6),"")

  • Adjust B6 and C6 to reference the cells containing your text and the specific character you want to count.

 

Count Case-Insensitive Characters Combining LEN, SUBSTITUTE, and UPPER Functions

Formula Breakdown

  • Determines the count of occurrences of a specific text in C6 within another text in B6. The formula converts both texts to uppercase using the UPPER function.
  • It substitutes all occurrences of the text in C6 with an empty string in the uppercase version of B5. The difference in the lengths of the original text in B6 and the modified text gives the count of occurrences of the text in C6 within B6.
  • It calculates how many times the specified text in C6 appears in the original text in B6, regardless case differences.

 


Example 3 – Count the Number of Occurrences of a Single Character in a Range

3.1- Using an Excel Built-in Function

To know the frequency of the character ‘A’ or ‘a’ in a data range.

  • Enter the following formula:

=SUM(LEN(B4:B10)-LEN(SUBSTITUTE(B4:B10,"a","")))

  • Adjust B4:B10 to reference your data range and specify the character you want to count. Here, “a”.
  • The SUM function adds all the numbers in a range of cells. The rest of the formula works as before and returns the total count of ‘a’ in the whole range.Count Number of Occurrences of a Single Character in a Range

Formula Breakdown

  • Replaces all “a” instances with an empty string, then subtracts the modified length from the original length in each cell, and sums the values.

3.2 – Using a User-Defined Function (UDF)

  • Press Alt+F11 to open the Visual Basic for Applications (VBA) editor.
  • Insert a new module by selecting Insert > Module.Open the Visual Basic for Applications (VBA) editor
  • Copy and paste the following code into the new Module.
    Function CountCharacter(rng As Range, character As String) As LongDim cell As Range
    Dim charCount As Long
    charCount = 0
    For Each cell In rng
    charCount = charCount + Len(cell.Value) - Len(Replace(cell.Value, character, "")
    Next cell
    CountCharacter = charCount
    End Function
  • Copy and paste the following code into the new Module.After closing the VBA editor, you can use the custom function in your Excel worksheet.
  • Select a cell.
  • Insert the following formula:

=CountCharacter(B4:B10,D4)

  • Adjust B4:B10 to reference your data range and specify the character you want to count in the D4.
  • Press Enter.Using a User-Defined Function (UDF) to count the occurrences of character

Example 4 – Count the Number of Occurrences of a Substring in a Range in Excel

To know the frequency of ‘Green’ :

  • Use this formula:

=SUM(LEN(B4:B10)-LEN(SUBSTITUTE(B4:B10,"Green","")))/LEN("Green")

Count Number of Occurrences of Substring in a Range in Excel

Formula Breakdown

  • Calculates the average number of occurrences of the word “Green” in B4:B10.
  • It replaces “Green” with an empty string, then subtracts the modified length from the original length in each cell.
  • It sums the values and divides them by the length of “Green,”, returning the average count of “Green” within the specified range.

Note: This is an array formula. Press CTRL+SHIFT+ENTER to enter it.


Download the Workbook

Download the practice workbook.


Frequently Asked Questions

Can characters be counted in a cell without including particular letters or symbols?

Yes, you can reduce the character count by excluding particular characters or symbols. Before utilizing the LEN function, remove those characters using the SUBSTITUTE function. Use the following formula:

=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1, "letter1", ""), "letter2", ""), "letter3", ""))

This formula determines the length of the text in A1 while excluding specified characters (‘letter1‘, ‘letter2‘, ‘letter3‘) through nested SUBSTITUTE functions. The LEN function calculates the resulting length

Are there any shortcuts to quickly count characters in a cell?

No, but you can quickly see the character count using the formula bar. When you click a cell, the formula bar shows you the character count, including spaces.

Can I count characters in cells that are part of a table in Excel?

Yes. Formulas and functions work similarly within tables.

<< Go Back to Count Characters in Cell | String Manipulation | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Hosne Ara
Hosne Ara

Hosne Ara is a materials and metallurgical engineer who loves exploring Excel and VBA programming. To her, programming is like a time-saving superhero for dealing with data, files, and the internet. She's skilled in Rhino3D, Maxsurf C++, MS Office, AutoCAD, and Excel & VBA, going beyond the basics. With a B. Sc. in Materials and Metallurgical Engineering from Bangladesh University of Engineering and Technology, she's shifted gears and now works as a content developer. In this role, she... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo