Text and cleaning · About 5 minutes
Swap characters with SUBSTITUTE
SUBSTITUTE finds a piece of text inside a cell and swaps it for something else. =SUBSTITUTE( reads as "in B2, swap every $ for nothing".
It takes three parts: the cell, the old text, the new text. Both texts go in quotes. Two quotes with nothing between them, "", mean "nothing", so the old text is simply removed.
The result is still text. Wrap it in VALUE when you need a number: =VALUE(.
VALUE on its own can often read your computer's own currency sign, like $ on a US computer, but not other signs or words like USD. Removing the sign first works everywhere.
Part of Plus
Free during our founding launch: sign in to unlock this lesson's exercises, the timed practice sets and the rest of Plus. The free lessons stay free, with no account needed.
What SUBSTITUTE does
SUBSTITUTE finds a piece of text inside a cell and swaps it for something else. Swap it for nothing, written as two quotes "", and you remove it, which makes SUBSTITUTE the usual way to remove characters like dashes, dots or unwanted words.
It is handy for cleaning codes, phone numbers and product names so they match another list, or so they fit a system that wants only digits. The result is text, so wrap it in VALUE when you need a number.
How to write SUBSTITUTE
=SUBSTITUTE(
- text
- The cell to change, like A2.
- old_text
- The text to look for, in quotes. Capitals matter:
"a"does not matchA. - new_text
- The text to put in its place, in quotes. Use
""to remove the old text. - instance_num
- Which match to swap, like 2 for the second one only. The square brackets mean it's optional: leave it out and SUBSTITUTE swaps every match.
SUBSTITUTE worked example
A delivery system wants phone numbers as digits only. In B2, remove the dots from A2, then fill down to B4.
| A | B | |
|---|---|---|
| 1 | Phone | Digits |
| 2 | 555.201.3344 | 5552013344 |
| 3 | 555.870.1029 | 5558701029 |
| 4 | 555.312.0077 | 5553120077 |
=SUBSTITUTE( A2, ".", "")In A2, swap every dot for nothing: the first row shows 5552013344. Filled down, the column shows 5558701029 and 5553120077.Common SUBSTITUTE mistakes
Nothing changes
SUBSTITUTE only swaps an exact match, and capitals count. Check that the old text is typed the way it appears in the cell, like "Ltd" rather than "LTD".
Every match changes when you wanted one
Add the fourth part, the instance number. With 1 at the end, only the first match is swapped and the rest stay.
The cleaned numbers won't add up
SUBSTITUTE always gives text. Wrap it in VALUE to turn the result into a number before you total it.
SUBSTITUTE, REPLACE or TRIM?
Use SUBSTITUTE when you know what the text says, like every dash. Use REPLACE when you know where it sits instead: it swaps a number of characters from a position, whatever they are. Both work in Excel and Google Sheets.
For extra spaces, TRIM is simpler: it keeps one space between words. And when the goal is a number, VALUE turns the cleaned text into one.
Questions people ask
How do I remove a specific character in Excel?
Replace it with nothing: =SUBSTITUTE( removes every dash.
How do I remove the dollar sign from a number?
If the $ is typed in as text, use =VALUE( to get a number. If the cell is a number shown in currency format, change the format instead.
What is the difference between SUBSTITUTE and REPLACE?
SUBSTITUTE swaps text you name, wherever it appears. REPLACE swaps the characters at a position you give, whatever they are.
Why didn't SUBSTITUTE replace anything?
It matches exactly and is case-sensitive, so "kg" won't match "KG", and an extra space stops a match.
How do I replace only the second occurrence?
Add the occurrence number as a fourth part: =SUBSTITUTE(.