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)| Argument | What it means | |
|---|---|---|
old_text | Required | The original text or cell. |
start_num | Required | Position of the first character to replace. |
num_chars | Required | How many characters to remove. Use 0 to insert without removing anything. |
new_text | Required | The 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
| A | B | |
|---|---|---|
| 1 | Old code | |
| 2 | PRD-2025-0458 | PRD-2026-0458 |
Result: PRD-2026-0458
Characters 5-8 (2025) are removed and 2026 is put in their place.
2Insert a hyphen
| A | B | |
|---|---|---|
| 1 | SKU | |
| 2 | NYC1042 | NYC-1042 |
Result: NYC-1042
With num_chars = 0, nothing is removed: the hyphen is inserted before character 4.
3Delete a fixed prefix
| A | B | |
|---|---|---|
| 1 | Invoice | |
| 2 | INV-7731 | 7731 |
Result: 7731
The first four characters INV- are replaced by nothing.
4Mask a phone number
| A | B | |
|---|---|---|
| 1 | Phone | |
| 2 | 6945123456 | ******3456 |
Result: ******3456
All but the last four characters are replaced by the same number of asterisks, built with REPT.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#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_numis beyond the end of the text,new_textis 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.
| Language | Function name |
|---|---|
| Czech | NAHRADIT |
| Danish | ERSTAT |
| Dutch | VERVANGEN |
| Finnish | KORVAA |
| French | REMPLACER |
| German | ERSETZEN |
| Hungarian | CSERE |
| Italian | RIMPIAZZA |
| Norwegian (Bokmål) | ERSTATT |
| Polish | ZASTĄP |
| Portuguese (Brazil) | MUDAR |
| Portuguese (Portugal) | SUBSTITUIR |
| Russian | ЗАМЕНИТЬ |
| Spanish | REEMPLAZAR |
| Swedish | ERSÄTT |
| Turkish | DEĞİŞTİR |