ID EN
#Text

SUBSTITUTE

Excel Functions

Replace text based on content

Syntax

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

Arguments

Parameter Description
text The text to change.
old_text The text to replace.
new_text The text to replace with.
instance_num [optional] The instance to replace. If not supplied, all instances are replaced.

Return Value

The processed text

Details

The SUBSTITUTE function is a way to perform a find‑and‑replace with a formula. Use it when you know what text you want to change, but you don’t know (or care) where it appears in a text string. By default, SUBSTITUTE will replace all instances of a text string with another text string. Optionally, you can specify which instance of text to replace by providing a number. To completely remove matched text (old_text), enter an empty string ("") for the new_text argument. The SUBSTITUTE function is used to replace one text string with another using a generic syntax like this: Where text is the value to process (typically a cell reference), old_text is the text to find, new_text is the text to replace with, and instance_num is an optional argument to target only a specific instance of old_text b

Examples

Example #1 - Basic usage

The SUBSTITUTE function is used to replace one text string with another using a generic syntax like this:

EXCEL
=SUBSTITUTE(text,old_text,new_text,[instance_num])
Example #1 - Basic usage

Where text is the value to process (typically a cell reference), old_text is the text to find, new_text is the text to replace with, and instance_num

EXCEL
=SUBSTITUTE(B5,"t","b") // replace all t's with b's
=SUBSTITUTE(B6,"t","b",1) // replace first t with b
=SUBSTITUTE(B7,"t","b") // replace all t's with b's
=SUBSTITUTE(B8,"cat","dog") // replace cat with dog
=SUBSTITUTE(B9,"#","") // replace # with nothing
=SUBSTITUTE(B10,"-",", ") // replace hyphens with commas
Example #2 - Replace all

By default, the SUBSTITUTE function will replace all instances of one text string with another. You can see this behavior in the worksheet below, wher

EXCEL
=SUBSTITUTE(B5,".","-")
Example #3 - Replace nth instance

By default, SUBSTITUTE will replace all instances of one text string with another. The optional fourth argument, called instance_num, can be used to r

EXCEL
=SUBSTITUTE(B5," ","-",2)
Example #4 - Replace line breaks

SUBSTITUTE can be combined with other functions to solve more difficult problems. The example below uses the SUBSTITUTE function to replace line break

EXCEL
=SUBSTITUTE(B5,CHAR(10),", ")
Example #5 - Remove unwanted text

You can use the SUBSTITUTE function to completely remove unwanted text by providing an empty string for the new_text argument. You can see this approa

EXCEL
=SUBSTITUTE(B5:B16,"*","")+0

See Also

REPLACE REGEXREPLACE