Text function

REPLACE function

Replaces part of a text string, chosen by position and length, with different text. Also used to insert or delete characters.

Available in All versions of Excel, including Microsoft 365, Excel for Mac and Excel for the web

In every Excel versionWorks in Google Sheets

Syntax

REPLACE(old_text, start_num, num_chars, new_text)
ArgumentWhat it means
old_textRequiredThe original text or cell.
start_numRequiredPosition of the first character to replace.
num_charsRequiredHow many characters to remove. Use 0 to insert without removing anything.
new_textRequiredThe text to put in. Use "" to delete.

Returns: The changed text.

How REPLACE works

REPLACE edits text by position. You say "starting at character 5, take out 4 characters and put this in their place", and it returns the new string. It is the right tool when the part you want to change is always in the same place, such as the year in PRD-2025-0458, a prefix, or the first digits of an ID you need to mask.

It doubles as an insert and delete tool: with num_chars set to 0 nothing is removed, so the new text is inserted at start_num; with new_text set to "" the characters are simply deleted. If the text you want to change is identified by its content rather than its position, use SUBSTITUTE (exact text) or REGEXREPLACE (a pattern) instead.

REPLACE works on the text form of a value, so applying it to a number returns text.

Examples

1Update the year in product codes

B2fx=REPLACE(A2,5,4,"2026")
AB
1Old code
2PRD-2025-0458PRD-2026-0458

Result: PRD-2026-0458

Characters 5-8 (2025) are removed and 2026 is put in their place.

2Insert a hyphen

B2fx=REPLACE(A2,4,0,"-")
AB
1SKU
2NYC1042NYC-1042

Result: NYC-1042

With num_chars = 0, nothing is removed: the hyphen is inserted before character 4.

3Delete a fixed prefix

B2fx=REPLACE(A2,1,4,"")
AB
1Invoice
2INV-77317731

Result: 7731

The first four characters INV- are replaced by nothing.

4Mask a phone number

B2fx=REPLACE(A2,1,LEN(A2)-4,REPT("*",LEN(A2)-4))
AB
1Phone
26945123456******3456

Result: ******3456

All but the last four characters are replaced by the same number of asterisks, built with REPT.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#VALUE!start_num is less than 1 or num_chars is negative.Check the positions, especially when they come from FIND or LEN calculations.

Tips

  • If start_num is beyond the end of the text, new_text is simply added at the end.
  • REPLACE edits by position, SUBSTITUTE by content. A quick way to remember: REPLACE needs numbers, SUBSTITUTE needs the old text.
  • Phone numbers stored as numbers lose leading zeros; format them as text before masking.

Questions

What is the difference between REPLACE and SUBSTITUTE?

REPLACE changes the characters at a given position; SUBSTITUTE finds a given text and swaps it, wherever it is.

How do I insert text in the middle of a cell?

Use REPLACE with num_chars 0: =REPLACE(A2,4,0,"-") inserts a hyphen before the 4th character.

Google Sheets

REPLACE also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

REPLACE in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
CzechNAHRADIT
DanishERSTAT
DutchVERVANGEN
FinnishKORVAA
FrenchREMPLACER
GermanERSETZEN
HungarianCSERE
ItalianRIMPIAZZA
Norwegian (Bokmål)ERSTATT
PolishZASTĄP
Portuguese (Brazil)MUDAR
Portuguese (Portugal)SUBSTITUIR
RussianЗАМЕНИТЬ
SpanishREEMPLAZAR
SwedishERSÄTT
TurkishDEĞİŞTİR

Recipes that use REPLACE