The SUBSTITUTE function replaces specific text inside a cell with new text. =SUBSTITUTE(A2,"INV","ORD") turns INV-2026-0147 into ORD-2026-0147. Give it the cell, the text to find and the text to put in. Leave the new text empty, as in =SUBSTITUTE(A2,"-",""), to delete a character. It is case sensitive and replaces every match unless you name one.
Functions
Excel SUBSTITUTE Function: Syntax and Examples
Try this now
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Minnesota | |||
| 2 | California | |||
| 3 | New York | |||
| 4 | Florida | |||
| 5 | Illinois |
Ready to practice?
Apply what you just learned with interactive exercises.
This page covers the four arguments, how to replace only the first or second match, how to nest several replacements, how to count occurrences with LEN, and how SUBSTITUTE differs from REPLACE and from Find and Replace. It ends with the errors and a small job that cleans an export.
TL;DR
- The pattern is =SUBSTITUTE(text, old_text, new_text, [instance_num]). You name the text to find, not a position.
- Without instance_num, every match is replaced. With it, only that numbered match changes.
- Matching is case sensitive: "inv" will not find INV. SUBSTITUTE does not accept wildcards either.
- Use an empty string "" as new_text to remove characters.
- Nest SUBSTITUTE inside SUBSTITUTE to remove several different characters in one formula.
- =LEN(A2)-LEN(SUBSTITUTE(A2,"x","")) counts how many times "x" appears.
- Use REPLACE, not SUBSTITUTE, when you know the position and the text could be anything.
Table of Contents
- The sample data used on this page
- SUBSTITUTE syntax and arguments
- How to use Excel SUBSTITUTE to replace text
- Remove characters with SUBSTITUTE
- Replace only the first, second or last match
- Nest SUBSTITUTE to clean several characters
- Count occurrences with LEN and SUBSTITUTE
- Case sensitivity and wildcards
- SUBSTITUTE compared with REPLACE and Find and Replace
- Excel versions
- Errors and odd results
- What learners get wrong
- A worked job scenario: tidying an order export
- Practice
- FAQ
- Sources
The sample data used on this page
Every example uses this short order export. Type it from A1.
| A | B | C | D | |
| 1 | Order ref | Phone | Address | Colors |
| 2 | INV-2026-0147 | (555) 123-4567 | 12 Oak St. | red, blue, red, green |
| 3 | INV-2026-0148 | (555) 987-6543 | 98 Elm St. | blue, blue, blue |
| 4 | INV-2026-0152 | 555.246.8135 | 7 Main St. | green |
| 5 | INV-2026-0153 | (555) 111-2222 | 40 Pine St. | red, green |
SUBSTITUTE syntax and arguments
=SUBSTITUTE(text, old_text, new_text, [instance_num])
| Argument | Required | What it does |
| text | Required | The text or cell to change. |
| old_text | Required | The text to look for. It must match exactly, including case. |
| new_text | Required | The text to put in its place. Use "" to delete. |
| instance_num | Optional | Which match to replace. If you leave it out, every match is replaced. |
How to use Excel SUBSTITUTE to replace text
Swap one word or prefix for another
=SUBSTITUTE(A2,"INV","ORD")
This returns ORD-2026-0147. Excel scans A2 for the exact text INV and writes ORD in its place. Everything around it stays put. Fill down and the other three refs change in the same way.
Replace every match
When there is more than one match and you leave instance_num out, all of them change:
=SUBSTITUTE(D2,"red","pink")
This returns pink, blue, pink, green. Both "red" entries became "pink". If one match is enough, add an instance number, shown below.
Expand an abbreviation
=SUBSTITUTE(C2,"St.","Street")
This returns 12 Oak Street. The period is part of the text to find, so "St." must match exactly. If some rows say "St" with no period, run a second SUBSTITUTE for that spelling.
Replace a separator with a line break
You can put a line break in as new text with CHAR(10):
=SUBSTITUTE(D2,", ",CHAR(10))
This returns the four colors on four lines. Turn on Wrap Text to see them. Going the other way, =SUBSTITUTE(D2,CHAR(10),", ") replaces each line break with a comma and a space, which is the usual fix for text pasted from a web page or a form.
Remove characters with SUBSTITUTE
SUBSTITUTE has no delete mode. You delete by replacing with nothing, which is an empty pair of quotes.
=SUBSTITUTE(A2,"-","")
This returns INV20260147. Both hyphens are gone because every match is replaced. To strip spaces from an address:
=SUBSTITUTE(C2," ","")
This returns 12OakSt. with the full stop still in place. Removing every space is different from what TRIM does. TRIM leaves single spaces between words and only removes the extra ones, as the TRIM guide explains. Use SUBSTITUTE when you want all the spaces gone, for example in a phone number or a product code.
Web data often carries a non-breaking space, character 160, which looks like a space but is not one. TRIM leaves it alone. Replace it with an ordinary space first:
=SUBSTITUTE(A2,UNICHAR(160)," ")
On the sample data this returns INV-2026-0147 unchanged, since A2 contains no such character. On a column pasted from a web page, it can be what finally makes a lookup match.
Replace only the first, second or last match
The fourth argument picks which match to change. Count from the left, starting at 1.
=SUBSTITUTE(D2,"red","pink",2)
This returns red, blue, pink, green. The first "red" stays and the second changes. To change the hyphens in the order ref one at a time:
=SUBSTITUTE(A2,"-","/",1)
This returns INV/2026-0147, and =SUBSTITUTE(A2,"-","/",2) returns INV-2026/0147.
If the number is larger than the matches available, nothing happens and Excel gives the original text back. =SUBSTITUTE(D2,"red","pink",3) returns red, blue, red, green. There is no error, so a wrong count passes silently.
An instance number of zero or less is an error. =SUBSTITUTE(D2,"red","pink",0) returns #VALUE!.
Replace the last match
SUBSTITUTE counts from the left, so it has no "last" option. You can get one by counting the matches first. The count of hyphens in A2 is the length of the text minus the length without hyphens, and that count is the position of the last one:
=SUBSTITUTE(A2,"-","/",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))
This returns INV-2026/0147. A2 has two hyphens, so the instance number works out to 2, and the second hyphen is replaced. The same formula works when a cell has any number of hyphens.
Nest SUBSTITUTE to clean several characters
SUBSTITUTE handles one old_text at a time. To remove several different characters, feed the result of one into the next. B2 contains parentheses, a space and a hyphen:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2,"(",""),")","")," ",""),"-","")
This returns 5551234567. Read it from the inside out. The innermost call removes "(", the next removes ")", then the space, then the hyphen. Each step receives the text the step before it produced.
Row 4 uses dots in place of everything else. Add one more layer and the same formula cleans any of the phone formats on the sample sheet:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B4,"(",""),")","")," ",""),"-",""),".","")
This returns 5552468135 for B4. On the other rows the extra layer finds no dots and leaves the text as it was. Five layers is about the limit before the formula becomes hard to read. If you have more characters to clear, list them in cells and use a helper column, or use REGEXREPLACE in a recent Microsoft 365 build (see the regex guide).
Turn the result into a number
Because SUBSTITUTE returns text, a cleaned digit string is not a number. To use it in a sum, wrap it in VALUE:
=VALUE(SUBSTITUTE(A2,"INV-2026-",""))
This returns 147. The leading zero in "0147" goes away because the result is now a number. If you need to keep leading zeros, such as in a code, leave it as text.
Count occurrences with LEN and SUBSTITUTE
SUBSTITUTE with an empty replacement shortens the text by the length of everything it removed. Compare the lengths before and after, and the difference tells you how many characters were removed.
=LEN(D2)-LEN(SUBSTITUTE(D2,",",""))
This returns 3, the number of commas in "red, blue, red, green". Four colors, so add 1 for the number of items:
=LEN(D2)-LEN(SUBSTITUTE(D2,",",""))+1
This returns 4 for D2, 3 for D3, and 1 for D4. D4 has no comma, so the count of commas is 0.
For text longer than one character, divide by the length of what you searched for:
=(LEN(D2)-LEN(SUBSTITUTE(D2,"red","")))/LEN("red")
This returns 2. Removing the two "red" entries shortens D2 by 6 characters, and 6 divided by 3 is 2. Without the division you would get 6.
This counts text anywhere in the cell, including inside longer words. Counting "red" in "colored" would count the "red" at the end. For counting cells that meet a condition, see the COUNTIF guide. Our LEN guide covers the other half of the trick.
Case sensitivity and wildcards
SUBSTITUTE is case sensitive:
=SUBSTITUTE(A2,"inv","ORD")
This returns INV-2026-0147, unchanged, because "inv" in lowercase is not found in uppercase text. There is no error. To ignore case, make the text one case first and search for that case:
=SUBSTITUTE(UPPER(A2),"INV","ORD")
This returns ORD-2026-0147. The catch is that UPPER changes the whole cell, so the other letters are now capitals as well. If you must keep the original case elsewhere, either match the case exactly or use a helper column to check first.
Wildcards do not work. An asterisk is a plain asterisk:
=SUBSTITUTE(A2,"INV-*","")
This returns INV-2026-0147, unchanged, because SUBSTITUTE searches for a literal "INV-*" and finds none. To remove everything from a fixed point on, use LEFT, MID or REPLACE, which work by position. The LEFT function guide and the MID function guide cover them.
SUBSTITUTE compared with REPLACE and Find and Replace
REPLACE has the syntax REPLACE(old_text, start_num, num_chars, new_text). It swaps a stretch of characters that you locate by position, regardless of what the characters say.
=REPLACE(A2,1,3,"ORD")
This returns ORD-2026-0147. It replaced the first three characters. And =REPLACE(A2,5,4,"2027") returns INV-2027-0147, changing the four characters that start at position 5.
| SUBSTITUTE | REPLACE | Find and Replace (Ctrl+H) | |
| Finds by | The text itself | Position and length | The text itself |
| Case sensitive | Always | Not applicable | Optional (Match case box) |
| Wildcards | No | Not applicable | Yes (* and ?) |
| Nth match | Yes (instance_num) | No | No |
| Updates when data changes | Yes | Yes | No, it edits the cells once |
| Keeps the original | Yes | Yes | No |
Excel versions
SUBSTITUTE works the same in Excel 2010 through Microsoft 365, in Excel for the web and on Mac. Nothing here needs a recent build, except REGEXREPLACE, which is a newer Microsoft 365 function. Check that your build has it before you rely on it in a shared file.
Errors and odd results
| What you see | Cause | Fix |
| Text did not change | Case mismatch, or the text is not there | Match the case exactly, or use UPPER or LOWER on both sides |
| #VALUE! | instance_num is zero or negative | Use 1 or higher |
| #NAME? | The function name is misspelled | Check the spelling: S-U-B-S-T-I-T-U-T-E |
| Wrong text replaced | A shorter old_text also matches inside other words | Make old_text longer, for example include a space |
| A cleaned number will not add | SUBSTITUTE returned text | Wrap it in VALUE |
| Stray space remains | The space is character 160 | Replace UNICHAR(160) with a normal space |
| Wildcard did nothing | SUBSTITUTE does not support wildcards | Use position-based functions |
| An error inside the cell | The source cell holds an error | Fix the source, or wrap in IFERROR |
What learners get wrong
Between 26 September and 3 November 2026, learners made 1,679 first attempts across our SUBSTITUTE Function lesson, and 66.2% were right. The hardest screen asked for a formula that turns "Bookkeeper" into "Beekeeper." It had 165 first attempts and only 29.7% were right. Answers below are shown as stored, in lowercase.
Replacing too little. The answer =substitute(a1,"o","e") appeared 55 times, and =substitute(a1,"oo","ee") appeared 38 times. Both give Beekkeeper, with a doubled k. Bookkeeper has two k's and Beekeeper has one, so the old text must include one of them: replace "ook" with "ee". The accepted answers were =substitute(a1,"ook","ee") and =substitute(a1,"Book","Bee"). Spell out the old and new strings letter by letter before you type. Another 5 attempts used "ook" with "eek", which keeps the extra k.
Case that does not match. The screen that changes "York" to "Jersey" had 179 first attempts and 55.3% were right. The answer =substitute(a3,"york","jersey") appeared 27 times, and =substitute(a3,"YORK","JERSEY") appeared 16 times. The cell holds "York" with a capital Y and lowercase letters after it, so only "York" matches. The same thing happened on the "Suffix" screen, with 164 first attempts and 67.1% right: =substitute(a1,"pre","suf") appeared 17 times. SUBSTITUTE did not find "pre" in "Pre", so nothing changed.
New text with the wrong case, or too short. On the same "Suffix" screen, =substitute(a1,"Pre","Su") appeared 5 times and =substitute(a1,"pre","Suf") 5 times. The first gives a replacement that is a letter short of the target, and the second again misses on case. The old text and the new text are both exact strings.
Old and new swapped. The answer =substitute(a1,"suf","pre") appeared 4 times. The second argument is what you look for and the third is what you put there. A quick check: read the formula aloud as "in A1, find this, put that."
Typing the answer, and misspelling the name. Three first attempts typed the result by hand instead of writing a formula. Another =substitue(a1,"Bookkeeper","Beekeeper") appeared 3 times, and =subtitute(a3,"York","Jersey") appeared 3 times. Each gives #NAME?. Excel suggests function names as you type, so pick the name from the list rather than spelling it.
One screen asked for "committed" without the instance argument, and the common slip was a one-letter search: =substitute(a1,"e","d") appeared 13 times where the accepted answer was =substitute(a1,"ee","ed"). With no instance number, a single "e" is replaced everywhere it appears in the word, not just at the end. On the sample data, =SUBSTITUTE(D2,"red","pink") shows the default at work, since both matches change.
A worked job scenario: tidying an order export
The shop is moving to a new numbering scheme and a new phone system. The export in the sample data needs four clean-ups before it can be imported.
- New order references. In E2 enter =SUBSTITUTE(A2,"INV","ORD") and fill down. E2 returns ORD-2026-0147. The numbering stays the same and only the prefix changes.
- Sort keys without hyphens. In F2 enter =SUBSTITUTE(A2,"-","") and fill down. F2 returns INV20260147. The key sorts and compares as one block.
- Clean phone numbers. In G2 enter the five-layer formula:
G2 returns 5551234567 and fill down gives G4 as 5552468135.
- Count the colors per order. In H2 enter =LEN(D2)-LEN(SUBSTITUTE(D2,",",""))+1 and fill down. The four rows return 4, 3, 1 and 2. To count one color in D3, use =(LEN(D3)-LEN(SUBSTITUTE(D3,"blue","")))/LEN("blue"), which returns 3.
- Freeze the results. Copy E2:H5 and use Paste Special, Values. Then you can delete the original columns. Keep a copy of the original sheet before you paste values over anything.
This job uses only SUBSTITUTE and LEN. Note that step 3 returns text. If the import wants a number, wrap it in VALUE, and expect the phone number to lose any leading zero.
Practice
Open the SUBSTITUTE Function lesson and type each formula yourself. The screens reward careful reading: match the case, count the characters, and say the arguments out loud. Next, the FIND function lesson shows how to locate text before you change it, and the LEN, LEFT, RIGHT, MID practice covers the position-based alternatives.
FAQ
How do I use SUBSTITUTE in Excel?
Type =SUBSTITUTE(A2,"old","new"). The first argument is the cell, the second is the text to find, and the third is the text to put in. For example, =SUBSTITUTE(A2,"INV","ORD") changes INV-2026-0147 to ORD-2026-0147. Every match is replaced unless you add a fourth argument.
How do I replace only the second occurrence in Excel?
Add the instance number as the fourth argument. =SUBSTITUTE(D2,"red","pink",2) changes only the second "red" in the cell and leaves the first. Count from the left, starting at 1. If the number is larger than the number of matches, nothing changes.
Is SUBSTITUTE case sensitive?
Yes. =SUBSTITUTE(A2,"inv","ORD") does not change INV-2026-0147, because lowercase "inv" does not match uppercase INV. To ignore case, wrap the cell in UPPER or LOWER and search for that case, such as =SUBSTITUTE(UPPER(A2),"INV","ORD").
What is the difference between SUBSTITUTE and REPLACE?
SUBSTITUTE finds text by what it says. REPLACE swaps characters by their position and length. =REPLACE(A2,1,3,"ORD") replaces the first three characters whatever they are. Use SUBSTITUTE when you know the text and REPLACE when you know where it sits.
How do I remove a character from a cell in Excel?
Use SUBSTITUTE with an empty string as the new text: =SUBSTITUTE(A2,"-","") removes every hyphen from INV-2026-0147. To remove several characters, nest one SUBSTITUTE inside another. To strip all spaces, use =SUBSTITUTE(C2," ","").
Can SUBSTITUTE use wildcards?
No. An asterisk or question mark is treated as a literal character. =SUBSTITUTE(A2,"INV-*","") looks for the exact text "INV-*" and finds none. Use Find and Replace (Ctrl+H) for wildcards, or position-based functions such as LEFT, MID and REPLACE.
How do I count how many times a character appears in a cell?
Subtract the length of the text without that character from the original length: =LEN(D2)-LEN(SUBSTITUTE(D2,",","")) returns 3 commas for D2. For longer text, divide by the length of the text you searched for.
Sources
Keep going
Guides people read next.

WEEKDAY Function in Excel: Syntax, Examples and Day Names
Learn how the Excel WEEKDAY function works, which return_type to pick, how to get day names, flag weekends and fix errors, with copy-ready formulas.
15 min
CHOOSECOLS Function in Excel: Syntax, Examples, Fixes
Learn how the Excel CHOOSECOLS function works, with CHOOSEROWS too: syntax, negative indexes, FILTER combos, version support and fixes for #VALUE! and #SPILL!.
16 minExcel FIND Function: Syntax, Examples and Fixes
Use the Excel FIND function to get a character's position, split text at @ or hyphens, find the second match, and fix #VALUE! errors.
16 min