Skip to content

SUBSTITUTE

Replaces specific text inside a string with other text. It matches case exactly and can target one occurrence.

Syntax

=SUBSTITUTE(, , , )

Text

All versions of Excel.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
1
SKU
Product
Compact code
2
FX-1010-BLK
Nitrile gloves
FX1010BLK
3
FX-1085-RED
Floor cleaner
4
5

C2 =SUBSTITUTE(A2,"-","") returns FX1010BLK

How SUBSTITUTE works

SUBSTITUTE replaces specific text inside a string with other text. Use it to strip dashes from a code, swap one word for another, turn line breaks into spaces, or change just the second dash in a reference. It finds text by what it says, not where it sits. For position-based edits, use REPLACE.

The arguments

  • text is the text to change.
  • old_text is what to look for. The match is case-sensitive.
  • new_text is the replacement. An empty string "" removes the old text.
  • instance_num is optional. Without it, SUBSTITUTE replaces every occurrence. With 2, only the second occurrence changes.

=SUBSTITUTE("FX-1010-BLK","-","") returns FX1010BLK. =SUBSTITUTE("PW-24-0113","-","/",2) returns PW-24/0113, because only the second dash was replaced.

Case matters

=SUBSTITUTE("Ltd and LTD","ltd","Limited") changes nothing, because neither word is spelled ltd. If case should not matter, make both sides the same case first. =SUBSTITUTE(LOWER(A2),"ltd","limited") finds every spelling, at the price of turning the whole text into lower case. SUBSTITUTE has no wildcards either: * and ? are ordinary characters.

Several replacements in a row

SUBSTITUTE changes one piece of text per call, so to change several, nest the calls. =SUBSTITUTE(SUBSTITUTE(A2," ",""),"-","") removes both spaces and dashes. Excel works from the inside out, so the inner result becomes the first argument of the outer call. For many replacements, a nest of four or five is the practical limit for readability. In Microsoft 365, you can keep it readable with LET.

Common jobs

  • Remove characters. Replace with "", as in the dash example above.
  • Change line breaks into spaces. =SUBSTITUTE(A2,CHAR(10)," "). CLEAN would delete the line break and join the words.
  • Replace non-breaking spaces. Web data often has character 160, which looks like a space but isn't one. TRIM leaves it alone. =SUBSTITUTE(A2,UNICHAR(160)," ") converts it.
  • Count a character. Compare the length with and without it: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")).

SUBSTITUTE and REPLACE

Use SUBSTITUTE when you know what to change. Use REPLACE when you know where. =REPLACE(A2,1,3,"NSW") overwrites the first three characters, whatever they were. SUBSTITUTE with the same old and new text swaps every match, wherever it appears.

What it returns

SUBSTITUTE always returns text, even if the result looks like a number. After removing a thousands comma from "1,250", you get "1250" as text. Wrap it in VALUE to turn it into a number. If old_text is not found, SUBSTITUTE returns the original text unchanged and doesn't show an error.

Arguments

text
The text to change. Usually a cell such as A2.
old_text
The text to replace. The match is case-sensitive, and * and ? are ordinary characters, not wildcards.
new_text
What to put in its place. Use "" to delete old_text.
instance_numoptional
Which occurrence of old_text to replace: 1 for the first, 2 for the second, and so on. If you leave it out, every occurrence is replaced.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Remove a character

C2 =SUBSTITUTE(A2,"-","")

Result: FX1010BLK

Replacing the dash with an empty string deletes every dash.

C2
A
B
C
1
SKU
Product
Compact code
2
FX-1010-BLK
Nitrile gloves
FX1010BLK
3
FX-1085-RED
Floor cleaner
4
5

C2 =SUBSTITUTE(A2,"-","") returns FX1010BLK

Example 2

Replace only one occurrence

C2 =SUBSTITUTE(A2,"-","/",2)

Result: PW-24/0113

instance_num 2 limits the change to the second dash. Without it, both dashes would become slashes.

C2
A
B
C
1
Batch code
Qty
Reformatted
2
PW-24-0113
400
PW-24/0113
3
4

C2 =SUBSTITUTE(A2,"-","/",2) returns PW-24/0113

Example 3

Nest two calls to remove two characters

C2 =SUBSTITUTE(SUBSTITUTE(A2," ",""),"-","")

Result: 0255500142

The inner SUBSTITUTE removes the space. The outer one removes the dash from the result. The answer is text, so the leading zero stays.

C2
A
B
C
1
Phone
Contact
Digits only
2
02 5550-0142
Front desk
0255500142
3
4

C2 =SUBSTITUTE(SUBSTITUTE(A2," ",""),"-","") returns 0255500142

Example 4

Replace a non-breaking space

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

Result: Floor cleaner

The space in A2 is character 160, which TRIM cannot remove. UNICHAR(160) names it so SUBSTITUTE can swap it for an ordinary space.

C2
A
B
C
1
Web export
Qty
Fixed
2
Floor cleaner
24
Floor cleaner
3
4

C2 =SUBSTITUTE(A2,UNICHAR(160)," ") returns Floor cleaner

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, return the SKU in A2 with the dashes removed. Fill it down to B5.

Answer in B2, then it fills down to B5.

B2
A
B
C
D
1
SKU
Compact
Phone
Digits only
2
FX-1010-BLK
02 5550-0142
3
FX-1085-RED
03 5550-0187
4
FX-2040-GRN
07 5550-0219
5
FX-3012-BLU
08 5550-0334
6
7

Common mistakes

  • SUBSTITUTE is case-sensitive. =SUBSTITUTE(A2,"ltd","Limited") leaves "LTD" and "Ltd" alone. Convert with LOWER first, or nest one call per spelling.
  • There are no wildcards. =SUBSTITUTE(A2,"*","") removes literal asterisks, not "anything".
  • If old_text isn't found, the result is the original text with no error. A formula that seems to do nothing usually has a spelling, case or hidden-character difference. Check with =LEN(A2).
  • The result is text. A cleaned number such as "1250" won't be counted by SUM. Wrap the formula in VALUE.
  • Characters that look like spaces may be non-breaking spaces (character 160). TRIM ignores them, so use SUBSTITUTE(A2,UNICHAR(160)," ").
  • Leaving out instance_num replaces every match. If you meant to change only one, give its number.

Questions people ask

How do I remove a character from text in Excel?

Replace it with an empty string: `=SUBSTITUTE(A2,"-","")`. To remove several characters, nest the calls: `=SUBSTITUTE(SUBSTITUTE(A2,"-","")," ","")`.

What is the difference between SUBSTITUTE and REPLACE?

SUBSTITUTE finds text by its content: "replace every dash". REPLACE works by position: "overwrite 3 characters starting at position 1". Use SUBSTITUTE when the text is known and REPLACE when the location is known.

Is SUBSTITUTE case-sensitive?

Yes. `"Ltd"` and `"LTD"` are different. To ignore case, convert the text with LOWER or UPPER before substituting, and use the same case for old_text.

How do I replace only the first or second occurrence?

Use the fourth argument: `=SUBSTITUTE(A2,"-","/",2)` replaces only the second dash. Leave it out to replace all of them.

Why did SUBSTITUTE not remove the space?

The space may be a non-breaking space, character 160, which looks identical. Use `=SUBSTITUTE(A2,UNICHAR(160),"")`. A trailing line break needs `CHAR(10)` instead.

Learn SUBSTITUTE in a real sheet.

SUBSTITUTE is taught in Logic and text, lesson 9: SUBSTITUTE. Each lesson is a short, graded exercise like the one above.