SUBSTITUTE vs REPLACE in Excel: Clean and Transform Text Data

SUBSTITUTE Vs. REPLACE Function in Excel feature image for tutorial blog
Learn when to use SUBSTITUTE vs REPLACE in Excel. SUBSTITUTE matches by content, REPLACE by position. Covers nested SUBSTITUTE, Nth occurrence, data masking, and more.

Data cleaning often comes down to two tasks: replacing a specific word or character wherever it appears, or replacing a chunk of text at a known position. Excel provides a dedicated function for each. SUBSTITUTE matches text by content — you tell it what to look for. REPLACE, by contrast, works by position — you tell it where to start and how many characters to overwrite. Choosing the right one makes your formula shorter, clearer, and far less likely to break as data changes.

Availability: Both SUBSTITUTE and REPLACE work in every Excel version from Excel 2000 onwards, including Microsoft 365, Excel 2024, 2021, 2019, and 2016.

What Do SUBSTITUTE and REPLACE Do?

The core decision is simple. SUBSTITUTE asks: "What text do you want to swap?" REPLACE asks: "Which characters, by position, do you want to overwrite?" Consequently, SUBSTITUTE is ideal for cleaning inconsistent data — removing dashes from phone numbers, stripping currency symbols, or standardising spellings. REPLACE, however, shines when text always sits at a fixed position — updating a year code in a product reference, masking digits in an ID, or inserting a prefix.

FeatureSUBSTITUTEREPLACE
Replace byMatching text contentCharacter position and length
Case sensitivityCase-sensitiveNot applicable — uses position
Replace Nth onlyYes — instance_num argumentNo — targets one fixed range
Best forRemoving/swapping known characters and wordsOverwriting a fixed position regardless of content
Syntax=SUBSTITUTE(text, old, new, [instance])=REPLACE(text, start, num_chars, new)

What Is the Syntax for Each Function?

Each function takes a different set of arguments that reflect its approach to replacement.

SUBSTITUTE — replace by matching text: =SUBSTITUTE(text, old_text, new_text, [instance_num]) REPLACE — replace by position: =REPLACE(old_text, start_num, num_chars, new_text)
ArgumentFunctionWhat it does
text / old_textBothThe source string to modify. Usually a cell reference.
old_textSUBSTITUTEThe exact character or substring to find and replace. Case-sensitive.
new_textBothThe replacement text. Use "" (empty string) to delete the matched characters.
instance_numSUBSTITUTE onlyOptional. Which occurrence to replace — 1 for first, 2 for second. Omit to replace all.
start_numREPLACE onlyThe character position where replacement begins. Character 1 is the first character.
num_charsREPLACE onlyHow many characters to overwrite. Use 0 to insert text without removing anything.
SUBSTITUTE is case-sensitive: =SUBSTITUTE(A2,"GB","UK") replaces "GB" but not "gb" or "Gb". If your data has inconsistent capitalisation, clean it first with UPPER or LOWER before applying SUBSTITUTE.

Example 1: Remove Unwanted Characters with SUBSTITUTE

Removing a character means substituting it with an empty string. This technique cleans dashes from phone numbers, strips currency symbols, removes spaces from codes, and deletes any other character that should not be there. SUBSTITUTE removes every instance of the character by default.

1
Strip formatting characters from phone numbers and product codes
Before — inconsistent formats

+44 (020) 7946-0832

PRD - 2026 - GB

$1,250.00

After — cleaned output

+442079460832

PRD-2026-GB

1250.00

Remove all spaces from a phone number: =SUBSTITUTE(A2, " ", "") Remove spaces AND parentheses — nest two SUBSTITUTE calls: =SUBSTITUTE(=SUBSTITUTE(A2,"(",""),")","") Remove spaces around the hyphens in a product code: =SUBSTITUTE(A2, " ", "") Strip the dollar sign and commas from a currency string: =SUBSTITUTE(=SUBSTITUTE(A2,"$",""),",","")
Using "" as the new_text argument tells SUBSTITUTE to simply delete the matched character. All instances are removed. The original cell is unchanged — the formula returns the cleaned text in a new cell.

Example 2: Replace a Specific Word or Phrase

SUBSTITUTE replaces words and phrases just as easily as single characters. It scans the entire string and swaps every matching occurrence. This is useful for standardising terminology, correcting bulk misspellings, or updating outdated labels across a dataset.

2
Standardise department names and update outdated labels
A — Original text
B — Formula
C — Result
Sales & Marketing
=SUBSTITUTE(A2,"Marketing","Growth")
Sales & Growth
Invoice 2024-001
=SUBSTITUTE(A3,"2024","2026")
Invoice 2026-001
Status: Pending
=SUBSTITUTE(A4,"Pending","Approved")
Status: Approved
Replace a word — swap "Marketing" with "Growth" everywhere in A2: =SUBSTITUTE(A2, "Marketing", "Growth") Update a year label in document references: =SUBSTITUTE(A2, "2024", "2026") Case-sensitive — "pending" and "Pending" are different. Use UPPER first if capitalisation varies: =SUBSTITUTE(UPPER(A2), "PENDING", "APPROVED")
SUBSTITUTE replaces ALL occurrences by default: If "2024" appears twice in a string, both are replaced. To replace only the first or a specific occurrence, use the fourth argument — for example, =SUBSTITUTE(A2,"2024","2026",1) replaces only the first match. Example 3 covers this in detail.

Example 3: Replace Only the Nth Occurrence

The optional fourth argument in SUBSTITUTE controls which specific occurrence to replace. For instance, a string like "cat-cat-dog" contains "cat" twice. Passing 1 replaces only the first "cat", and passing 2 replaces only the second. This is particularly useful for fixing the second delimiter in a multi-part code without changing the first.

3
Replace the 2nd hyphen only — convert a code segment without touching the first
A — Code
Replace 1st "-" only
Replace 2nd "-" only
Replace all "-"
PRD-GB-2026
PRD_GB-2026
PRD-GB_2026
PRD_GB_2026
Replace ALL hyphens (default — no 4th argument): =SUBSTITUTE(A2, "-", "_") PRD-GB-2026 → PRD_GB_2026 Replace the FIRST hyphen only (instance_num = 1): =SUBSTITUTE(A2, "-", "_", 1) PRD-GB-2026 → PRD_GB-2026 Replace the SECOND hyphen only (instance_num = 2): =SUBSTITUTE(A2, "-", "_", 2) PRD-GB-2026 → PRD-GB_2026 Clever trick — use instance_num with a unique marker to locate the Nth occurrence. Replace the 2nd hyphen with a unique character, then FIND its position: FIND("#", =SUBSTITUTE(A2, "-", "#", 2)) Returns position of the 2nd hyphen — useful for nested MID extractions

Example 4: Overwrite a Fixed Position with REPLACE

REPLACE is the right choice when you know the position of the characters to change, regardless of what those characters contain. For example, if a product reference always has a 4-digit year starting at character 5, REPLACE can update that year in one formula — even when the year values differ across rows.

4
Update a year code at a fixed position across all product references
A — Old reference
Chars 5–8
B — Updated
PRD-2024-GB
2024
PRD-2026-GB
SVC-2023-US
2023
SVC-2026-US
HW-2025-APAC
2025
HW-2026-APAC
All codes have the year at position 5, length 4. REPLACE overwrites 4 characters starting at character 5 with "2026": =REPLACE(A2, 5, 4, "2026") Works regardless of what the original year was. Replace the first letter in a file path (e.g. change drive letter C → D): =REPLACE(A2, 1, 1, "D") C:\reports\q1.xlsx → D:\reports\q1.xlsx Insert text without deleting — set num_chars to 0: Adds "NEW-" before character 1 without removing anything. =REPLACE(A2, 1, 0, "NEW-") PRD-GB-2026 → NEW-PRD-GB-2026
REPLACE does not care what the original characters say — it simply overwrites them. In contrast, SUBSTITUTE would need to match each year value (2023, 2024, 2025) separately. REPLACE handles all of them in one formula because the position stays the same.

Example 5: Mask Sensitive Data with REPLACE

REPLACE is ideal for masking personal or financial data. You can overwrite middle digits of a credit card, phone number, or ID with asterisks. Furthermore, combining REPLACE with LEN makes the mask dynamic — it adjusts automatically to strings of any length.

5
Mask the middle digits of an ID or credit card number
A — Full value
B — Masked output
Approach
4111-1111-1111-1234
4111-****-****-1234
Fixed mask
AB-123456789
AB-*****6789
Keep last 4
Mask characters 6 to 15 of the card number with asterisks: =REPLACE(A2, 6, 9, "****-****") 4111-1111-1111-1234 → 4111-****-****-1234 Dynamic mask — keep first 2 and last 4, mask everything in between. LEN(A2)-6 calculates how many middle characters to overwrite: =REPLACE(A2, 3, LEN(A2)-6, REPT("*", LEN(A2)-6)) Show last 4 digits only — mask everything else: REPT repeats "*" for LEN minus 4 characters. =REPLACE(A2, 1, LEN(A2)-4, REPT("*", LEN(A2)-4))
REPT generates the asterisk string dynamically: =REPT("*", 5) returns "*****". Combining REPT with LEN means the mask always matches the number of characters being replaced — useful when ID lengths vary across rows.

Example 6: Nested SUBSTITUTE for Multiple Replacements

SUBSTITUTE replaces only one type of character per call. However, nesting multiple SUBSTITUTE functions inside each other lets you clean several characters in a single formula. Each inner SUBSTITUTE feeds its result to the next one, so all replacements happen in sequence.

How to Nest SUBSTITUTE

The innermost SUBSTITUTE runs first. Its output becomes the text argument of the next SUBSTITUTE. Additionally, you can combine nesting with LET to avoid repeating the cell reference and to make the logic easier to follow.

6
Clean multiple characters in one formula — spaces, dashes, slashes, and commas
Input — messy imported data

01/04/2026 - London, UK

+44 (0)20-7946 0832

Output — standardised

01-04-2026 London UK

+442079460832

Replace "/" with "-", then remove commas and extra spaces: =SUBSTITUTE( =SUBSTITUTE( =SUBSTITUTE(A2, "/", "-"), ",", ""), " ", " ") Cleaner with LET — each step named and readable: LET( s1, =SUBSTITUTE(A2, "(", ""), s2, =SUBSTITUTE(s1, ")", ""), s3, =SUBSTITUTE(s2, "-", ""), s4, =SUBSTITUTE(s3, " ", ""), s4 ) +44 (0)20-7946 0832 → +442079460832 Count word occurrences using SUBSTITUTE and LEN: Subtract the string length without "cat" from the total, divide by length of "cat". =(LEN(A2)-LEN(=SUBSTITUTE(A2,"cat",""))) / LEN("cat")

How to Fix Common Errors

SUBSTITUTE returns the original text unchanged

The most common cause is a case mismatch. SUBSTITUTE is case-sensitive, so "pending" does not match "Pending". Check the exact capitalisation of the text in the cell. Alternatively, normalise first with UPPER or LOWER, then apply SUBSTITUTE to the standardised version.

REPLACE returns wrong characters

Either start_num or num_chars is off by one. To verify, use MID to inspect exactly what sits at that position: =MID(A2, start_num, num_chars). If MID returns the correct segment, REPLACE will overwrite it correctly. Adjust the numbers until MID shows the right characters.

Formula returns a text string instead of a number

SUBSTITUTE and REPLACE always return text, even when the result looks like a number. Therefore, if you need to use the result in arithmetic, wrap the formula in VALUE: =VALUE(SUBSTITUTE(A2,"$","")). Alternatively, multiply the result by 1 to trigger an automatic conversion.

Non-breaking spaces: Imported data sometimes contains non-breaking space characters (Unicode 160) that look identical to regular spaces but TRIM cannot remove. Use SUBSTITUTE to replace them first: =SUBSTITUTE(A2, CHAR(160), " "), then wrap with TRIM to clean up all remaining spaces.

Frequently Asked Questions

  • What is the difference between SUBSTITUTE and REPLACE in Excel?+
    SUBSTITUTE replaces text by matching its content — you specify what to look for. REPLACE, by contrast, replaces text by position — you specify where to start and how many characters to overwrite. Use SUBSTITUTE when you know the exact text to remove or swap. Use REPLACE when you know the position of the characters to change, regardless of what those characters contain.
  • How do I delete a character using SUBSTITUTE?+
    Use an empty string "" as the new_text argument: =SUBSTITUTE(A2, "-", ""). This replaces every hyphen with nothing, effectively deleting it. By default, all occurrences are removed. To remove only the first occurrence, add 1 as the fourth argument: =SUBSTITUTE(A2, "-", "", 1).
  • How do I replace only the second occurrence with SUBSTITUTE?+
    Use the fourth argument, instance_num. For example, =SUBSTITUTE(A2, "-", "_", 2) replaces only the second hyphen and leaves all others unchanged. Pass 1 for the first occurrence, 2 for the second, and so on. When the fourth argument is omitted, all occurrences are replaced.

More Questions About SUBSTITUTE and REPLACE

  • Is SUBSTITUTE case-sensitive?+
    Yes, SUBSTITUTE is case-sensitive. It treats "Apple", "apple", and "APPLE" as three different strings. Consequently, a formula looking for "Pending" will not match "pending". To work around this, apply UPPER or LOWER to the source text first, then run SUBSTITUTE on the normalised version. REPLACE, by contrast, is not affected by case because it works by position.
  • How do I insert text at a specific position using REPLACE?+
    Set num_chars to 0. This tells REPLACE to insert the new text at the specified start position without removing any existing characters. For example, =REPLACE(A2, 1, 0, "NEW-") inserts "NEW-" at the very beginning of the string in A2 without changing the rest.
  • Which Excel versions support SUBSTITUTE and REPLACE?+
    Both functions are available in every Excel version from Excel 2000 onwards, including Microsoft 365, Excel 2024, 2021, 2019, 2016, 2013, 2010, and 2007. They also work in Excel for the web and Google Sheets. No special version or add-in is required.