To swap text inside a formula — reformat phone numbers, fix a recurring typo, change a delimiter — use SUBSTITUTE (replace by matching text) or REPLACE (replace by position). Unlike Find & Replace, these update automatically as data changes.
The example
Reformat dashed codes into spaced ones.
| A | B | |
|---|---|---|
| 1 | Raw | Replaced |
| 2 | A-100-X | A 100 X |
| 3 | B-205-Y | B 205 Y |
The formula
Dashes replaced with spaces:
How it works
SUBSTITUTE matches text; REPLACE matches position:
SUBSTITUTE(text, old, new)finds everyoldstring and swaps innew— all dashes become spaces.- Add a 4th argument to target a specific occurrence:
SUBSTITUTE(A2, "-", " ", 2)changes only the 2nd dash. REPLACE(text, start, length, new)works by position instead — replace 3 characters starting at position 1, regardless of what they are.- Both rebuild the string live, so editing the source updates the result.
SUBSTITUTE vs Find & Replace. The Ctrl+H dialog is a one-time edit of the cells themselves; SUBSTITUTE is a live formula that keeps reformatting as the source changes — better for ongoing imports.
Try it: interactive demo
Set the text, what to find, and what to replace it with.
Variations
Replace only the Nth occurrence
The 4th argument targets one instance:
Remove text entirely
Replace with an empty string:
REPLACE by position
Swap the first 3 characters for a new prefix:
Pitfalls & errors
SUBSTITUTE is case-sensitive. “cat” won’t match “Cat.” Match the exact case, or normalize with LOWER first.
SUBSTITUTE matches text; REPLACE matches position. Use SUBSTITUTE when you know what to change, REPLACE when you know where.
Nested SUBSTITUTEs get unreadable. For many swaps, stack them carefully or use a lookup table approach instead.
Practice workbook
Frequently asked questions
How do I replace text within a formula in Excel?
What's the difference between SUBSTITUTE and REPLACE?
How do I replace only one occurrence?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class