How SUBSTITUTE works in Excel? Best SUBSTITUTE examples

How SUBSTITUTE works in Excel? Best SUBSTITUTE examples

One of my favorite functions in Excel is the SUBSTITUTE function. It’s incredibly useful when dealing with text manipulation. Whether I need to replace a specific word, remove unwanted characters, or clean data quickly, SUBSTITUTE is my go-to tool.

What is the SUBSTITUTE function in Excel?

The SUBSTITUTE function in Excel replaces occurrences of a specific text string within a larger text string. Unlike REPLACE, which removes characters based on position, SUBSTITUTE works based on text values.

Here’s the basic syntax:

=SUBSTITUTE(text, old_text, new_text, [instance_num])
  • text – The original text where replacements will occur.
  • old_text – The text that needs to be replaced.
  • new_text – The text to replace with.
  • instance_num (optional) – Specifies which occurrence of old_text to replace. If omitted, all occurrences are replaced.

Basic Example: Replacing Words

Let’s start with a simple example. Suppose I have this text in cell A1:

Excel is amazing!

If I want to replace “amazing” with “powerful,” I use:

=SUBSTITUTE(A1, "amazing", "powerful")

This results in:

Excel is powerful!

Replacing All Occurrences of a Word

Imagine I have this text:

I love apples. Apples are my favorite fruit.

To replace “Apples” with “Oranges,” I use:

=SUBSTITUTE(A1, "Apples", "Oranges")

The issue? “Apples” is capitalized in one instance but lowercase in another. SUBSTITUTE is case-sensitive, so “apples” won’t change. To ensure all cases are covered, I nest LOWER:

=SUBSTITUTE(LOWER(A1), "apples", "oranges")

This converts everything to lowercase before replacing.

Replacing Specific Occurrences

Let’s say I have:

Red, Blue, Blue, Green

If I only want the second “Blue” changed to “Yellow,” I use:

=SUBSTITUTE(A1, "Blue", "Yellow", 2)

Now, my new text is:

Red, Blue, Yellow, Green

Removing Unwanted Characters

When dealing with messy data, I often need to strip unnecessary characters. For example, suppose I have phone numbers containing dashes, and I want only digits:

123-456-7890

The formula to remove dashes:

=SUBSTITUTE(A1, "-", "")

This cleans up the number:

1234567890

Using SUBSTITUTE with Other Functions

SUBSTITUTE becomes even more powerful when combined with other functions.

Replacing Line Breaks

When dealing with imported data, I often come across unwanted line breaks. Fortunately, SUBSTITUTE can handle these by replacing CHAR(10) (line break character) with a space:

=SUBSTITUTE(A1, CHAR(10), " ")

Using SUBSTITUTE with LEN

If I want to count how many times a word appears, I use a trick with LEN:

= (LEN(A1) - LEN(SUBSTITUTE(A1, "word", ""))) / LEN("word")

This formula calculates how often “word” appears in cell A1.

Common Mistakes and Limitations

While SUBSTITUTE is powerful, it has some limitations:

  • It is case-sensitive – This sometimes produces unexpected results.
  • It does not support wildcards – Unlike SEARCH or FIND, you cannot use * or ?.
  • It only works with text – Numbers inside text are fine, but it won’t work on pure numeric values.

SUBSTITUTE vs REPLACE

SUBSTITUTE and REPLACE may seem similar, but they serve different purposes. Here’s a comparison:

Function Works Based On Primary Use
SUBSTITUTE Text occurrences Replaces specific words or characters
REPLACE Character position Replaces text based on start position and length

If I need to change “abc123” to “abcXYZ,” both functions can help, but I would use:

=SUBSTITUTE(A1, "123", "XYZ")

Or, if I know “123” starts at position 4:

=REPLACE(A1, 4, 3, "XYZ")

Conclusion

SUBSTITUTE is one of the most useful functions in Excel for dealing with text replacement. Whether removing unwanted characters, replacing specific words, or processing data efficiently, this function can save time and effort. Understanding how it works and experimenting with different use cases makes working with Excel much smoother.

 

Other interesting article:

How SEARCH works in Excel? Best SEARCH examples