How to use the SUBSTITUTE function
Formula in cell E3:
The SUBSTITUTE function replaces a specific text string in a value. It is case sensitive meaning it differentiates between upper and lower letters.
The image above shows the SUBSTITUTE function cell E3 substituting the word "red" with "brown" based on value in cell B3.
Table of Contents

 SUBSTITUTE Function Syntax
 SUBSTITUTE Function Arguments
 SUBSTITUTE function example
 SUBSTITUTE function wildcard
 SUBSTITUTE function quotation mark
 Substitute multiple strings
 SUBSTITUTE function from right
 Substitute all letters with a given string
 SUBSTITUTE function all numbers
 SUBSTITUTE function based on table
 Get Excel *.xlsx file
1. SUBSTITUTE Function Syntax
SUBSTITUTE(text, old_text, new_text, [instance_num])
2. SUBSTITUTE Function Arguments
text  Required. The value you want to substitute text in. 
old_text  Required. The text string you are looking for in the value. 
new_text  Required. The text you want to substitute. 
[instance_num]  Optional. Which instance to replace. If not entered every instance is substituted. 
3. SUBSTITUTE function example
The SUBSTITUTE function, in the above example, substitutes the word "brown" with "red" at the second found instance. Cell B6 contains "brown", cell C6 contains "red" and cell D6 contains 2 representing which instance to replace.
Formula in cell B9:
4. SUBSTITUTE function wildcard
You can't use wildcard characters in the SUBSTITUTE function, however, you can use the builtin feature "Find and Replace" to do the same thing.
You can use the following characters:
 ? (question mark)  a single character
 * (asterisk)  any number of characters zero included
Here are the steps to use the "Find and Replace" dialog box:
 Select a cell range you want to use.
 Press CTRL + H to open the "Find and Replace" dialog box.
 Type the search string in " Find what:".
 Type the substitution string in "Replace with:".
 Press with the left mouse button on the "Replace" button to replace strings in a single cell.
Press with the left mouse button on the "Replace All" button to replace strings in all cells on the active worksheet.
5. How to substitute quotation marks
The image above demonstrates how to remove quotation marks using the SUBSTITUTE function.
Formula in cell B6:
6. How to substitute multiple strings
You can nest the SUBSTITUTE function to substitute multiple values in one calculation, however, the formula grows quickly if you have many strings to substitute.
Formula in cell B6:
Explaining formula
Step 1  Substitute first string
SUBSTITUTE(B3, D6, E6)
becomes
SUBSTITUTE("A red fox", "red", "grey")
and returns "A grey fox".
Step 2  Substitute second string
SUBSTITUTE(SUBSTITUTE(B3, D6, E6), D7, E7)
becomes
SUBSTITUTE("A grey fox", D7, E7)
becomes
SUBSTITUTE("A grey fox", "fox", "wolf")
and returns "A grey wolf".
Recommended reading
Substitute multiple text strings [UDF]
7. SUBSTITUTE function from right
Formula in cell B6:
Explaining formula
Step 1  Substitute string with nothing
SUBSTITUTE(B3, D6, "")
becomes
SUBSTITUTE("55512 34 12 56 12 78 12 90",12,"")
and returns
"555 34 56 78 90".
Step 2  Count characters
The LEN function counts the number of characters.
LEN(value)
LEN(SUBSTITUTE(B3, D6, ""))
becomes
LEN("555 34 56 78 90")
and returns 19. "555 34 56 78 90" contains 19 characters.
Step 3  Count characters in cell B3
LEN(B3)
becomes
LEN("55512 34 12 56 12 78 12 90")
and returns 27.
Step 4  Subtract character counts
LEN(B3)LEN(SUBSTITUTE(B3, D6, ""))
becomes
27  19 equals 8.
Step 5  Divide with old text character count
The division character lets you divide numbers in an Excel formula. The parentheses allow you to control the order of calculation.
(LEN(B3)LEN(SUBSTITUTE(B3, D6, "")))/LEN(D6)
becomes
(27  18)/LEN(12)
becomes
(27  18)/2
becomes
8/2 equals 4. There are four instances of value 12 in cell B3. "55512 34 12 56 12 78 12 90"
Step 6  Substitute value based on instance
SUBSTITUTE(B3, D6, D9, (LEN(B3)LEN(SUBSTITUTE(B3, D6, "")))/LEN(D6))
becomes
SUBSTITUTE("55512 34 12 56 12 78 12 90", 12, "AA", 4)
and returns "55512 34 12 56 12 78 AA 90".
8. Substitute all letters with a given string
This formula substitutes all letters, upper and lower letters, to a given string.
Array formula in cell B6:
The last part of the formula contains the string you want to use, bolded in the formula below.
TEXTJOIN(, TRUE, IF(ISERROR(SEARCH(MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")), MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), ""))
8.1 How to enter an array formula
Excel 365 users may enter the formula as a regular formula, no need to follow the steps below.
 Copy above formula
 Double press with the left mouse button on cell B3, a prompt appears.
 Paste the formula.
 Press and hold CTRL + SHIFT simultaneously.
 Press Enter once.
 Release all keys.
The formula bar contains a leading and trailing curly bracket if you followed the above steps, it indicates that the formula is an array formula. Don't enter these characters yourself.
8.2 Explaining formula
Step 1  Count characters
The LEN function counts the number of characters.
LEN(value)
LEN(B3)
becomes
LEN("ABC12 VF 12 56 12 aC 12 90")
and returns 27.
Step 2  Create a cell ref
The INDEX function lets you build a dynamic cell reference.
INDEX(A:A, LEN(B3))
becomes
INDEX(A:A, 27)
and returns A27.
Step 3  Create a cell ref to a cell range
The colon character lets you append a cell ref to a cell ref.
A1:INDEX(A:A, LEN(B3))
returns A1:A27.
Step 4  Create row numbers
The ROW function calculates the row number of a cell reference.
ROW(ref)
ROW(A1:INDEX(A:A, LEN(B3)))
becomes
ROW(A1:A27)
and returns {1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27}.
Step 5  Create an array containing each character in cell B3
The MID function returns a substring from a string based on theÂ starting position and the number of characters you want to extract.
MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1)
becomes
MID("ABC12 VF 12 56 12 aC 12 90", {1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20; 21; 22; 23; 24; 25; 26; 27}, 1)
and returns
{"A"; "B"; "C"; ""; "1"; "2"; " "; "V"; "F"; " "; "1"; "2"; " "; "5"; "6"; " "; "1"; "2"; " "; "a"; "C"; " "; "1"; "2"; " "; "9"; "0"}.
Step 6  Calculate position of each character in the alphabet
The SEARCH function returns a number representing the position of character at which a specific text string is found reading left to right. It is not a casesensitive search.
SEARCH(find_text,within_text, [start_num])
SEARCH(MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
becomes
SEARCH({"A"; "B"; "C"; ""; "1"; "2"; " "; "V"; "F"; " "; "1"; "2"; " "; "5"; "6"; " "; "1"; "2"; " "; "a"; "C"; " "; "1"; "2"; " "; "9"; "0"}, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
and returns
{1; 2; 3; #VALUE!; #VALUE!; #VALUE!; #VALUE!; 22; 6; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; 1; 3; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!}
Note that the SEARCH function returns an error value if the character is not found in the alhpabet.
Step 7  Find error values in the array
The ISERROR function returns TRUE if a value is an error value.
ISERROR(value)
ISERROR(SEARCH(MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
becomes
ISERROR({1; 2; 3; #VALUE!; #VALUE!; #VALUE!; #VALUE!; 22; 6; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; 1; 3; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!; #VALUE!})
and returns
{FALSE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}.
Step 8  Replace TRUE with the corresponding character
The Boolean value FALSE will be replaced with a "" character.
IF(ISERROR(SEARCH(MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")), MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "")
becomes
IF({FALSE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}, MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "")
becomes
IF({FALSE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; FALSE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}, {"A"; "B"; "C"; ""; "1"; "2"; " "; "V"; "F"; " "; "1"; "2"; " "; "5"; "6"; " "; "1"; "2"; " "; "a"; "C"; " "; "1"; "2"; " "; "9"; "0"}, "")
and returns
{"";"";"";"";"1";"2";" ";"";"";" ";"1";"2";" ";"5";"6";" ";"1";"2";" ";"";"";" ";"1";"2";" ";"9";"0"}.
Step 9  Concatenate characters
The TEXTJOIN function concatenates cell values.
TEXTJOIN(delimiter,Â ignore_empty,Â text1,Â [text2], ...)
TEXTJOIN(, TRUE, IF(ISERROR(SEARCH(MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")), MID(B3, ROW(A1:INDEX(A:A, LEN(B3))), 1), ""))
becomes
TEXTJOIN(, TRUE, {"";"";"";"";"1";"2";" ";"";"";" ";"1";"2";" ";"5";"6";" ";"1";"2";" ";"";"";" ";"1";"2";" ";"9";"0"})
and returns "12  12 56 12  12 90".
Excel 365 dynamic array formula in cell B6:
9. Substitute all numbers with a given character/string
Array formula in cell
Read section 8 for an formula explanation.
10. Substitute all characters except numbers and letters
The image above demonstrates an array formula that replaces all characters except upper and lower letters and digits to a given string, in this example .
Array formula in cell B6:
Read section 8 for a formula explanation.
11. SUBSTITUTE function based on table
The formula in cell C3 substitutes the value in cell B3 using the table in cells E2:F5. This formula works if only one string is found, it returns a blank if nothing is found.
Array formula in cell C3:
Explaining formula
Step 1  Search for each old string in the table simultaneously
The SEARCH function returns a number representing the position of character at which a specific text string is found reading left to right. It is not a casesensitive search.
SEARCH(find_text,within_text, [start_num])
SEARCH($E$3:$E$5, B3)
becomes
SEARCH({"red";"yellow";"blue"},"A red fox")
and returns {3; #VALUE!; #VALUE!}. This means that the first value "red" in the array is found at character position 3 in "A red fox".
Step 2  Find errors
The ISNUMBER function returns TRUE if a value is a number.
ISNUMBER(value)
ISNUMBER(SEARCH($E$3:$E$5, B3))
becomes
ISNUMBER({3; #VALUE!; #VALUE!})
and returns {TRUE; FALSE; FALSE}.
Step 3  Substitute strings
SUBSTITUTE(B3, $E$3:$E$5, $F$3:$F$5)
becomes
SUBSTITUTE("A red fox",{"red"; "yellow"; "blue"},{"brown"; "pink"; "black"})
and returns
{"A brown fox"; "A red fox"; "A red fox"}.
Step 4  Replace TRUE with the corresponding value
The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.
IF(logical_test, [value_if_true], [value_if_false])
IF(ISNUMBER(SEARCH($E$3:$E$5, B3)), SUBSTITUTE(B3, $E$3:$E$5, $F$3:$F$5), "")
becomes
IF({TRUE; FALSE; FALSE}, {"A brown fox"; "A red fox"; "A red fox"}, "")
and returns
{"A brown fox"; ""; ""}.
Step 5  Concatenate strings
The TEXTJOIN function concatenates cell values.
TEXTJOIN(delimiter,Â ignore_empty,Â text1,Â [text2], ...)
TEXTJOIN("", TRUE, IF(ISNUMBER(SEARCH($E$3:$E$5, B3)), SUBSTITUTE(B3, $E$3:$E$5, $F$3:$F$5), ""))
becomes
TEXTJOIN("", TRUE, {"A brown fox"; ""; ""})
and returns "A brown fox".
'SUBSTITUTE' function examples
The following 12 articles contain the SUBSTITUTE function.
Table of Contents Count a specific text string in a cell Count text string in a range (case sensitive) Count […]
This article demonstrates formulas that count values in cell based on a delimiting character. The image above shows a formula […]
Question: How do I count how many times a word exists in a range of cells? It does not have […]
This article demonstrates an array formula that counts how many times multiple text strings exist in a cell range.Â The […]
Question: How do I count the number of times a text string exists in a column? The text string may […]
Table of Contents Extract the last word Extract the last letter Extract the last number Get Excel *.xlsx file 1. […]
The formula displayed above in cell range D3:D9 extracts a word based on its position in a cell value. For […]
Question: How to extract email addresses from this sheet? Answer: It dependsÂ on how the emails are populated in your worksheet? […]
This article demonstrates array formulas that search for cell values containing a search string and returns corresponding values on the […]
This article demonstrates formulas and a UDF that searches for values in a table based on concatenated values and returns […]
This blog article describes how to split strings in a cell with space as a delimiting character, like Text to […]
What's on this page Reverse text Insert random characters Convert letters to numbers How to shuffle characters in the alphabet […]
Functions in this article
Functions in 'Text' category
The SUBSTITUTE function function is one of many functions in the 'Text' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form