What SUBSTITUTE does
SUBSTITUTE replaces one piece of text with another wherever it appears in a cell. =SUBSTITUTE(A2," ","") swaps every space in A2 for nothing, so the VAT number DE 291 834 576 becomes DE291834576. It’s the usual way to strip characters out of codes and phone numbers, or to change a separator on every row.
It finds the text by what it is, wherever it sits, and changes every copy unless the fourth argument names one. Its partner REPLACE works by position: you tell it where to start and how many characters to take out, which suits codes with a fixed layout.
SUBSTITUTE matches capitals exactly, and its result is always text, even when only digits are left.
Syntax
textRequired- The text to change, usually a cell such as
A2. old_textRequired- The characters to replace, in quotation marks, such as
"-"or" ". Capitals must match exactly:"ltd"doesn't findLtd. new_textRequired- What to put in their place. Use
"", empty text, to remove them. instance_numOptional- Which copy to replace, counting from the left:
1for the first,2for the second. Leave it out and every copy changes.
Example: VAT numbers without spaces
The invoicing system wants EU VAT numbers without spaces, and the customer list has them typed with spaces. The formula in B2 is filled down to B4.
Read it as: in A2, swap every " " for "", empty text. Changing "" to "-" would put a dash wherever there was a space instead.
Example: remove several characters at once
A dialer wants phone numbers as digits only, and the CRM has them typed with brackets, spaces and dashes. One SUBSTITUTE removes one character, so the formula nests four, each working on the result of the one inside it.
The number in A4 has no brackets, and the formula still works: a SUBSTITUTE that finds nothing to replace passes the text on unchanged. The results are text, which keeps any leading zero.
Replace only one copy
With a fourth argument, SUBSTITUTE changes only that copy, counting from the left. =SUBSTITUTE(A2,"-","/",2) turns UK-4471-B into UK-4471/B: the first dash stays and the second becomes a slash.
The same argument tells you where a second or third copy sits. Swap that copy for a character the text doesn’t contain, then ask FIND where it is: =FIND("#",SUBSTITUTE(A2,"-","#",2)) returns 8, the position of the second dash in UK-4471-B.
Common mistakes
=SUBSTITUTE(A2,"ltd","")leaves “Harbor Supplies Ltd” as it is, because the capitals don’t match. Type old_text the way it’s written in the cells.- Removing a word leaves the space next to it:
=SUBSTITUTE(A2,"Ltd","")turns “Harbor Supplies Ltd” into “Harbor Supplies ” with a space at the end. Put TRIM around it. - The result is text, even when it’s all digits.
=SUBSTITUTE(A2,",","")turns “1,250” into the text 1250, which SUM skips. Wrap it in VALUE to get a number:=VALUE(SUBSTITUTE(A2,",","")). - A space copied from a web page is often a non-breaking space, character 160, which
" "doesn’t match. Swap it for an ordinary space first:=SUBSTITUTE(A2,CHAR(160)," ").
Frequently asked questions
How do I substitute multiple values in Excel?
Nest one SUBSTITUTE inside another, one for each value: =SUBSTITUTE(SUBSTITUTE(A2,"(",""),")","") removes both kinds of bracket. Each one works on the result of the one inside it.
How do I remove a character from text in Excel?
Replace it with empty text: =SUBSTITUTE(A2,"-","") removes every dash in A2. Add a fourth argument, as in =SUBSTITUTE(A2,"-","",1), to remove only the first one.
What is the difference between SUBSTITUTE and REPLACE?
SUBSTITUTE finds text by what it is, such as every dash in a cell. REPLACE changes the characters at a position you give, such as the first three, whatever they are.
Is SUBSTITUTE case-sensitive?
Yes. "ltd" doesn’t match Ltd or LTD, so type old_text with the capitals the cells use, or nest one SUBSTITUTE for each spelling.
How do I count how many times a character appears in a cell?
Remove the character with SUBSTITUTE and compare the lengths: =LEN(A2)-LEN(SUBSTITUTE(A2,"-","")) returns 2 for UK-4471-B, one for each dash. The LEN page has more ways to count characters.