
What is SUBSTITUTE in Excel?
The SUBSTITUTE function replaces matching text within a string. It helps standardize punctuation, remove unwanted characters, change labels or clean imported codes without changing the source cell. Unlike REPLACE, which works with character positions, SUBSTITUTE works by finding specific text.
SUBSTITUTE syntax
=SUBSTITUTE(text,old_text,new_text,[instance_num])
text is the original string. old_text is the sequence to find; new_text is its replacement. The optional instance_num determines which occurrence to replace. Without it, all occurrences are replaced.
Example 1: Replace hyphens with spaces
If A2 contains New-Delhi-Office:
=SUBSTITUTE(A2,"-"," ")
Result: New Delhi Office. All hyphens are replaced because no occurrence number is specified.
Example 2: Remove a known character
If A2 contains INV#1045:
=SUBSTITUTE(A2,"#","")
Result: INV1045. An empty replacement string deletes the chosen character. This is useful for normalizing identifiers, but remove punctuation only if the cleaned identifier remains meaningful.
Example 3: Replace only the second occurrence
If A2 contains red-red-red:
=SUBSTITUTE(A2,"red","blue",2)
Result: red-blue-red. The fourth argument selects the second exact match. Without it, the result would be blue-blue-blue.
Example 4: Standardize a department name
If A2 contains Human Resources and your report uses HR:
=SUBSTITUTE(A2,"Human Resources","HR")
Result: HR. SUBSTITUTE is case-sensitive and also replaces matching text within longer strings, so use a carefully chosen rule.
Example 5: Remove nonbreaking spaces
If web data includes nonbreaking space characters (CHAR(160)):
=TRIM(SUBSTITUTE(A2,CHAR(160)," "))
The inner SUBSTITUTE converts the unusual spaces to ordinary ones; TRIM removes excess ordinary spaces. This can resolve some lookup mismatches caused by pasted web text.
Example 6: Count occurrences of a character
To count hyphens in A2, compare the length before and after removing them:
=LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))
For INV-2026-1045, the result is 2. This works for a one-character target. For longer substrings, divide the length difference by LEN of the target string.
Example 7: Nest SUBSTITUTE to replace two separators
Suppose A2 contains East|Sales;2026 and you want a comma-separated label:
=SUBSTITUTE(SUBSTITUTE(A2,"|",", "),";",", ")
Result: East, Sales, 2026. Each SUBSTITUTE call handles one old/new pair.
SUBSTITUTE versus REPLACE
SUBSTITUTE finds particular text anywhere within a string; REPLACE changes characters based on a start position and length. Use SUBSTITUTE when the marker is known, and REPLACE when the character position is reliably known.
Common SUBSTITUTE problems
- Unexpected case mismatch: SUBSTITUTE matches text case-sensitively; “HR” and “hr” are different.
- Accidental partial replacements: replacing “cat” also changes that substring inside longer words.
- Wrong instance number: instance_num refers to occurrence order, not character position.
- Numbers stored as text: replacing punctuation in numeric-looking text does not automatically produce a number; use VALUE if appropriate.
- Source still looks unchanged: the original cell is not edited by the formula; the result appears in the formula cell.
Frequently asked questions
Is SUBSTITUTE case-sensitive?
Yes. To standardize inconsistent case, consider combining with LOWER or UPPER when appropriate.
How do I remove all spaces?
Use =SUBSTITUTE(A2," ","") for ordinary spaces. This is different from TRIM, which preserves single spaces between words.
Can I replace just one occurrence?
Yes, supply instance_num as the fourth argument.
Practice exercise
Make a list of invoice IDs using hyphens and inconsistent separators. Create cleaned copies by replacing hyphens with spaces, removing a special marker, and replacing only the second matching separator.
Related Excel tutorials
Explore our Excel Functions module for more formula tutorials and real-world spreadsheet examples.
Official reference
For syntax and product-version details, consult Microsoft Excel Support.
