Pinterest Pixel

Count Text Occurrences with Excel’s SUBSTITUTE Formula

Bryan
What does it do?

What does it do?

It replaces specific text in a text string i.e. Substitutes new text for old text in a text string.

Formula breakdown:

=SUBSTITUTE(text, old_text, new_text, [instance num])

What it means:

=SUBSTITUTE(This cell, From this TEXT character, To this TEXT character, [In the 1st, 2nd…instance it occurs])


I had a scenario where I had to count the number of occurrences of a specific character in a cell.

For example, I had to check the number of asterisks * in a cell.  Why you ask?

Well it was because the asterisks corresponded to the number of times the employee was away that year.  Who would’ve thought of putting asterisks, but there you go!

At first, I had no clue on how to do this and it was very cumbersome to do this manually!

Turns out, the SUBSTITUTE formula in Excel can be used creatively to extract the count easily!

Here’s an example:

Count Text Occurrences with Excel's SUBSTITUTE Formula

We want to return the count of asterisks here, which is 7. We will use a combination of the LEN formula and the  SUBSTITUTE formula.

We will have 3 main steps:

  • Get the length of the entire string – in this case, the length of “Bradley Strickland *******” would be 26.
  • Get the length of the text without the asterisks – in this case, the length of “Bradley Strickland” would be 19.
  • Subtract the two lengths – this will give us 7, which is the number of asterisks.

I explain how you can do this and please go to the bottom of the page to see the animated gif tutorial:

Count Text Occurrences with Excel's SUBSTITUTE Formula | MyExcelOnline

download excel workbook SUBSTITUTE-Count-Text-Occurrences.xlsx

 

STEP 1: We need to use the SUBSTITUTE function to remove all of the asterisks from the text. We will replace the asterisk “*” with an empty string “”.

=SUBSTITUTE(C9, “*”, “”)

Count Text Occurrences with Excel's SUBSTITUTE Formula

You can see now that the asterisks are removed:

Count Text Occurrences with Excel's SUBSTITUTE Formula

 

STEP 2: With this result, we can get the length of the text without asterisks using the LEN function:

=LEN(SUBSTITUTE(C9, “*”, “”))

Count Text Occurrences with Excel's SUBSTITUTE Formula

The length of “Bradley Strickland” is 19:

Count Text Occurrences with Excel's SUBSTITUTE Formula

 

STEP 3: Now here is the cool part!

Since we have the length of the text without asterisks, we now get the length of the complete text with asterisks, then we subtract them together. This will give us the number of asterisk occurrences in the text!

=LEN(C9) – LEN(SUBSTITUTE(C9, “*”, “”))

Count Text Occurrences with Excel's SUBSTITUTE Formula

 

This formula gives us 26 – 19, wherein 26 is the length of the whole text, while 19 is the length of the text without asterisks.

This will give us 7, which is the exact number of asterisks in the text!

Count Text Occurrences with Excel's SUBSTITUTE Formula

 

STEP 4: Do the same for the rest of the cells by dragging the SUBSTITUTE formula all the way down using the left mouse button.

Note that all of the counts are automatically calculated:

Count Text Occurrences with Excel's SUBSTITUTE Formula

 

 

 

If you like this Excel tip, please share it



Count Text Occurrences with Excel's SUBSTITUTE Formula | MyExcelOnline


Bryan

Bryan Hong is an IT Software Developer for more than 10 years and has the following certifications: Microsoft Certified Professional Developer (MCPD): Web Developer, Microsoft Certified Technology Specialist (MCTS): Windows Applications, Microsoft Certified Systems Engineer (MCSE) and Microsoft Certified Systems Administrator (MCSA).

He is also an Amazon #1 bestselling author of 4 Microsoft Excel books and a teacher of Microsoft Excel & Office at the MyExecelOnline Academy Online Course.

See also  CountIf Formula in Excel

Star 30 Days - Full Access Star

One Dollar Trial

$1 Trial for 30 days!

Access for $1

Cancel Anytime

One Dollar Trial
  • Get FULL ACCESS to all our Excel & Office courses, bonuses, and support for just USD $1 today! Enjoy 30 days of learning and expert help.
  • You can CANCEL ANYTIME — no strings attached! Even if it’s on day 29, you won’t be charged again.
  • You'll get to keep all our downloadable Excel E-Books, Workbooks, Templates, and Cheat Sheets - yours to enjoy FOREVER!
  • Practice Workbooks
  • Certificates of Completion
  • 5 Amazing Bonuses
Satisfaction Guaranteed
Accepted paymend methods
Secure checkout

Get Video Training

Advance your Microsoft Excel & Office Skills with the MyExcelOnline Academy!

Dramatically Reduce Repetition, Stress, and Overtime!
Exponentially Increase Your Chances of a Promotion, Pay Raise or New Job!

Learn in as little as 5 minutes a day or on your schedule.

Learn More!

Share to...