Tabellab
Excel formulas

SUBSTITUTE vs REPLACE in Excel

=SUBSTITUTE(text, old_text, new_text, [instance_num]) finds a piece of text and swaps it for another, wherever it appears. =REPLACE(old_text, start_num, num_chars, new_text) ignores the content and overwrites a number of characters at a given position. So =SUBSTITUTE("079-123-45-67","-","") removes every dash and returns 0791234567, while =REPLACE("AB-2025-0417",4,4,"2026") overwrites characters 4 to 7 and returns AB-2026-0417. Rule of thumb: if you know what to change, use SUBSTITUTE; if you know where it is, use REPLACE. The example below runs twelve typical clean-up tasks through both, plus REGEXREPLACE for the cases where neither is convenient.

Updated 30 Oct 2026 6 min read By Tabellab team

Syntax and arguments

SUBSTITUTE takes the text, the text to look for, the text to put in its place and, optionally, which occurrence to change. Without the fourth argument every occurrence is replaced. With it, only that one: =SUBSTITUTE(A3,"green","teal",2) changes the second "green" in "red, green, blue, green" and leaves the first alone. An empty new_text ("") deletes the old text.

REPLACE takes the text, the position of the first character to change, how many characters to remove and the text to insert there. The inserted text can be longer or shorter than what it replaces. With num_chars 0 nothing is removed and REPLACE becomes an insert: =REPLACE("SKU48172",4,0,"-") returns SKU-48172. Positions count from 1, and spaces and punctuation count as characters.

Both functions return text, even when the result looks like a number. The original cell is never changed; the result appears in the formula cell, and you can paste it back as values when the clean-up is done.

SUBSTITUTE step by step: remove, swap, count

Removing characters. Replace them with an empty string. For several different characters, nest the calls: =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A6,"(",""),")",""),"-","") turns "(079) 123-4567" into "079 1234567". Each layer handles one character, working from the inside out.

Swapping separators. =PROPER(SUBSTITUTE(A5,"_"," ")) changes "anna_maria_keller" to "Anna Maria Keller": first the underscores become spaces, then PROPER capitalises each word. The same pattern converts semicolons to commas or dots to slashes.

Text amounts to numbers. "CHF 1,234.50" is text that cannot be summed. Remove the currency label and the thousands separator, then convert with VALUE: =VALUE(SUBSTITUTE(SUBSTITUTE(A7,"CHF ",""),",","")) returns the number 1,234.50. Without VALUE the result is still text, which the checks below the example confirm with ISNUMBER.

Counting occurrences. The length before minus the length after removing a character is the number of times it appears: =LEN(A8)-LEN(SUBSTITUTE(A8,"s","")) finds 4 in "Mississippi". Counting spaces and adding one gives the number of words, 4 in "red, green, blue, green".

SUBSTITUTE is case-sensitive. In "Apple apple APPLE" only the lowercase word matches "apple", so the result is "Apple pear APPLE". To replace every spelling, apply it to LOWER(A4) first, accepting that the whole text becomes lowercase, or use REGEXREPLACE with a case-insensitive pattern.

REPLACE step by step: overwrite, insert, mask

REPLACE is the right tool for codes with a fixed layout, where a part is always in the same place. In "AB-2025-0417" the year always occupies characters 4 to 7, so =REPLACE(A9,4,4,"2026") updates it without caring what the old year was. SUBSTITUTE(A9,"2025","2026") would also work here, but it would change every "2025" in the text, including one hiding in the serial number.

Combined with LEN, REPLACE can work from the end of the text. =REPLACE(A12,LEN(A12)-4,5,"draft") overwrites the last five characters of "Report_v3_final" whatever its total length. Combined with REPT it masks: =REPLACE(A11,1,LEN(A11)-4,REPT("*",LEN(A11)-4)) keeps the last four characters of a ticket number and turns the rest into stars, "******3947". Masking only hides characters in the displayed result; the original is still in the source cell, so it is no substitute for removing data you must not keep.

When the position is not fixed, find it first. FIND (case-sensitive) or SEARCH (not case-sensitive) return the position of a character, which you can pass to REPLACE as start_num. For pulling out the part between two characters, TEXTBEFORE and TEXTAFTER are simpler, see extract text between two characters.

Worked example: twelve text clean-ups with SUBSTITUTE, REPLACE and REGEXREPLACE

The original texts are inputs (yellow); each row states the goal and the function used. The checks below the list confirm what kind of value each formula returns.

Worked example: twelve text clean-ups with SUBSTITUTE, REPLACE and REGEXREPLACE
ABCD
1Original textGoalFunctionResult
2079-123-45-67Remove every dashSUBSTITUTE0791234567
3red, green, blue, greenChange only the 2nd "green"SUBSTITUTEred, green, blue, teal
4Apple apple APPLEReplace "apple" (case-sensitive)SUBSTITUTEApple pear APPLE
5anna_maria_kellerUnderscores to spaces, then capitalsSUBSTITUTEAnna Maria Keller
6(079) 123-4567Remove three different charactersSUBSTITUTE ×3079 1234567
7CHF 1,234.50Text amount to a numberSUBSTITUTE + VALUE1,234.50
8MississippiCount the letter "s"LEN − SUBSTITUTE4
9AB-2025-0417Overwrite characters 4–7 with 2026REPLACEAB-2026-0417
10SKU48172Insert a dash after character 3REPLACESKU-48172
11TK58213947Mask all but the last 4 charactersREPLACE + REPT******3947
12Report_v3_finalReplace the last 5 charactersREPLACE + LENReport_v3_draft
13079-123 45 67Keep only the digits (Excel 365)REGEXREPLACE0791234567
14
15Checks on the list aboveValue
16Words in "red, green, blue, green": spaces + 14
17Is the cleaned amount a real number? ISNUMBERyes
18Is the same text without VALUE a number?no
19Length of the phone number after removing dashes10
20Same result both ways? SUBSTITUTE ×3 vs REGEXREPLACE on (079) 123-4567same
Key formulas
  • D2=SUBSTITUTE(A2,"-","")Remove every dash
  • D3=SUBSTITUTE(A3,"green","teal",2)Only the 2nd occurrence
  • D7=VALUE(SUBSTITUTE(SUBSTITUTE(A7,"CHF ",""),",",""))Text amount to a number
  • D8=LEN(A8)-LEN(SUBSTITUTE(A8,"s",""))Count a character
  • D9=REPLACE(A9,4,4,"2026")Overwrite by position
  • D10=REPLACE(A10,4,0,"-")Insert without removing
  • D11=REPLACE(A11,1,LEN(A11)-4,REPT("*",LEN(A11)-4))Mask all but the last 4
  • D13=REGEXREPLACE(A13,"[^0-9]","")Keep only digits

Fictional codes and numbers. REGEXREPLACE needs Excel 365 or a recent version of Google Sheets; the other functions work in every version of Excel, Google Sheets and LibreOffice.

REGEXREPLACE and other alternatives

Excel 365 has =REGEXREPLACE(text, pattern, replacement), which replaces everything that matches a regular expression. =REGEXREPLACE(A13,"[^0-9]","") deletes every character that is not a digit, so "079-123 45 67" becomes 0791234567 in one step instead of a stack of SUBSTITUTEs. The last check in the example confirms it gives the same digits as the nested version. Regular expressions are powerful but harder to read, and older Excel versions do not have the function, so for one or two characters SUBSTITUTE remains the clearer choice.

For removing extra spaces use TRIM, and for non-printing characters from system exports use CLEAN; non-breaking spaces copied from web pages need SUBSTITUTE(A2,CHAR(160)," ") before TRIM can see them. Excel's Find & Replace dialog (Ctrl+H) does the same job as SUBSTITUTE on the cells themselves, without a formula, which is fine for a one-off clean-up but leaves no trace of what was changed.

Which one to use

Use SUBSTITUTE when you can name the text to change: separators, unwanted characters, a word, a specific occurrence, or counting how often something appears. Use REPLACE when you know the position: fixed-format codes, inserting a separator, overwriting the start or end, masking. Use REGEXREPLACE when the rule is a pattern, such as "all non-digits". All three leave the source untouched, so keep the original column until you have checked the results.

Common mistakes

  • Mixing up the argument order. SUBSTITUTE is (text, old, new, instance); REPLACE is (text, start, number of characters, new). Putting the new text second in REPLACE returns #VALUE!.
  • Forgetting that SUBSTITUTE is case-sensitive. "apple" does not match "Apple". Normalise with LOWER or UPPER first, or use REGEXREPLACE.
  • Expecting a number. Both functions return text, so SUM ignores "1234.50" produced by SUBSTITUTE. Wrap the result in VALUE.
  • Using REPLACE on text with a varying layout. Fixed positions break as soon as one code is a character longer. Find the position with FIND or SEARCH, or use SUBSTITUTE.
  • Replacing every occurrence by accident. SUBSTITUTE(A2,"25","26") also changes the 25 inside 2025. Use instance_num or REPLACE when only one occurrence should change.
  • Thinking masking deletes data. A masked result only hides characters in the formula cell; the full value remains in the source cell.

Frequently asked questions

What is the difference between SUBSTITUTE and REPLACE in Excel?

SUBSTITUTE replaces text you specify wherever it appears, or only a chosen occurrence. REPLACE replaces a number of characters at a given position, regardless of what they are.

How do I remove a character from text in Excel?

Replace it with an empty string: =SUBSTITUTE(A2,"-","") removes every dash. Nest SUBSTITUTE for several characters, or use REGEXREPLACE in Excel 365.

How do I replace only the second occurrence in Excel?

Use the fourth argument of SUBSTITUTE: =SUBSTITUTE(A2,"old","new",2) changes only the second occurrence and leaves the others as they are.

Is SUBSTITUTE case-sensitive?

Yes. SUBSTITUTE only matches text with exactly the same upper and lower case. Apply LOWER or UPPER to the text first if the case should not matter.

How do I count how many times a character appears in a cell?

Subtract the length without the character from the full length: =LEN(A2)-LEN(SUBSTITUTE(A2,"s","")) counts the letter s.

Practise it in a lab

Related guides

Reading is step one. Doing is step two.

Every guide links to a lab where you build the same calculation in an online spreadsheet and get instant feedback.

Open the lab