Text Formulas

How to Use the SUBSTITUTE Function in Excel

Swap one piece of text for another with SUBSTITUTE, replace only one occurrence, and see how it differs from REPLACE, with examples you can copy.

On this page
  1. What SUBSTITUTE does
  2. Replace all matches or only one
  3. Matching is case-sensitive
  4. Remove characters
  5. Swap line breaks and hidden spaces
  6. SUBSTITUTE versus REPLACE
  7. Chain several replacements
  8. Check your results

What SUBSTITUTE does

SUBSTITUTE finds a piece of text inside a cell and replaces it with new text. The syntax is:

=SUBSTITUTE(text, old_text, new_text, [instance_num])

The last argument is optional. Leave it out to replace every match.

For example, if A2 holds the code AB-123-XY, =SUBSTITUTE(A2,"-","/") returns AB/123/XY, because each dash is a match.

Replace all matches or only one

Without instance_num, every match changes. With it, only that occurrence changes:

  • =SUBSTITUTE(A2,"-","/") returns AB/123/XY, changing both dashes.
  • =SUBSTITUTE(A2,"-","/",2) returns AB-123/XY, changing only the second dash.

Matching is case-sensitive

SUBSTITUTE treats uppercase and lowercase letters as different. =SUBSTITUTE("Apple apple","apple","pear") returns “Apple pear”, because only the lowercase match is replaced.

If you need to replace text regardless of case, Find and Replace is an option for a one-off change. It ignores case unless you tick Match case.

Remove characters

Replacing text with an empty string deletes it:

=SUBSTITUTE(A2,"$","") removes a dollar sign.

For a value such as $1,250, nest a second SUBSTITUTE to remove the comma, then wrap the result in VALUE to make it a number:

=VALUE(SUBSTITUTE(SUBSTITUTE(A2,"$",""),",",""))

This returns 1250. Converting text to numbers is covered in how to convert text to number in excel.

Swap line breaks and hidden spaces

=SUBSTITUTE(A2,CHAR(10)," ") replaces each line break with a space. A non-breaking space, which often comes from web pages, is replaced the same way, using UNICHAR(160):

=SUBSTITUTE(A2,UNICHAR(160)," ")

For a broader cleanup, see remove non printing characters in excel.

SUBSTITUTE versus REPLACE

REPLACE works by position, not by the text it finds:

=REPLACE(old_text, start_num, num_chars, new_text)

For example, =REPLACE(A2,4,3,"XYZ") changes AB-123-XY to AB-XYZ-XY, by replacing the three characters that start at position 4.

Use REPLACE when you know where the characters sit. Use SUBSTITUTE when you know what they say.

Chain several replacements

You can nest SUBSTITUTE functions to make several changes in one formula. The innermost one runs first. Nested formulas get hard to read quickly. In newer versions of Excel, LET can give each step a name, and a let function in excel example shows how to set that up.

Check your results

SUBSTITUTE always returns text. If the cell holds a number and you need to add it later, convert it with VALUE. Test the formula on a few rows first, and check any row where the text might contain a second match or a special character.

The complete guide to text formulas

Text Formulas in Excel Explained
Read the guide

Keep exploring

Guides from other topics

All topics →