The Excel REPLACE function overwrites text by position: point at a starting character, say how many characters to overwrite, and hand it the new text. It doesn’t care what is there — only where — which makes it perfect for fixed-width codes, masking digits, and inserting separators. Its value-based twin is SUBSTITUTE.
1, overwrite 3 characters, write "469" in their place. Set num_chars to 0 and REPLACE inserts instead of overwriting.
Syntax
| Argument | Description | |
|---|---|---|
old_text | Required | The text (or cell reference) to work on. The original cell is never changed. |
start_num | Required | Position of the first character to overwrite. The first character is 1. |
num_chars | Required | How many characters to overwrite. 0 overwrites nothing — the new text is inserted. |
new_text | Required | The text to drop in. It can be longer or shorter than the stretch it replaces. |
REPLACE vs SUBSTITUTE: REPLACE works by position (“overwrite characters 1–3”); SUBSTITUTE works by value (“swap every hyphen”). If you know where the change goes, use REPLACE; if you know what to change, use SUBSTITUTE.
Overwrite by position
Every number in A2:A5 starts with the old 214 area code. REPLACE doesn’t need to know it’s “214” — it just overwrites characters 1 through 3:
| A | B | |
|---|---|---|
| 1 | Old number | New area code |
| 2 | 214-555-0147 | 469-555-0147 |
| 3 | 214-555-0198 | 469-555-0198 |
| 4 | 214-555-0023 | 469-555-0023 |
| 5 | 214-555-0061 | 469-555-0061 |
Because new_text can be any length, REPLACE also shortens or stretches text. Masking is the classic use — hide the middle digits of an ID:
Try it: interactive REPLACE demo
Drag the sliders to pick a position and length — the highlighted stretch is what gets overwritten.
Insert text, build dates, find the position with FIND
The insert trick. With num_chars set to 0, nothing is overwritten — the new text is wedged in at start_num. Turn a raw date stamp into a readable one with two nested inserts:
Add a separator to fixed-width product codes the same way:
Dynamic positions. Hard-coded positions break on variable-length text — let FIND locate the spot. Swap out everything after the @ in an email:
num_chars can safely overshoot — LEN(A2) just means “to the end.” And to delete a stretch, replace it with nothing:
Errors & common pitfalls
#VALUE! — bad position or length. start_num must be 1 or greater and num_chars must be 0 or greater. Zero or negative start_num, or a negative num_chars, returns #VALUE!.
Pitfall: using REPLACE when you mean SUBSTITUTE. =REPLACE(A2,"a","b",...) fails — REPLACE’s second argument is a number, not search text. To find-and-swap by value, you want SUBSTITUTE.
Pitfall: dates turn into serial numbers. Point REPLACE at a real date and it sees the underlying value — =REPLACE(A2,1,2,"30") on 11-Jun-2026 works on “46184”, not the display. Convert first with TEXT: =REPLACE(TEXT(A2,"yyyy-mm-dd"),...).
Pitfall: the result is text. Even when it looks numeric, REPLACE returns a text string. =REPLACE("1099",1,2,"20") gives the text “2099” — wrap it in VALUE() or prefix -- before doing math.
Pitfall: start_num past the end appends. If start_num is bigger than the text length, nothing is overwritten and new_text is simply tacked onto the end. No error, occasionally a surprise.
Practice workbook
Frequently asked questions
What's the difference between REPLACE and SUBSTITUTE?
How do I insert text without deleting anything?
num_chars to 0: =REPLACE(A2, 4, 0, "-") wedges a hyphen in front of character 4 and keeps every existing character. Two nested zero-length REPLACEs turn 20260611 into 2026-06-11.Can REPLACE find the text to replace by itself?
=REPLACE(A2, FIND("@",A2)+1, LEN(A2), "newdomain.com"). If you find yourself doing this often, SUBSTITUTE is usually the simpler tool.How do I mask part of a number, like a credit card or SSN?
=REPLACE(A2, 1, 5, "***-**") turns 123-45-6789 into ***-**-6789. Remember the result is text, and the original cell still holds the full value.Why does REPLACE on a date give me a weird number?
=REPLACE(TEXT(A2,"mm/dd/yyyy"), 1, 2, "07").Is REPLACE case-sensitive?
Master functions like this in one day
This page covers one function. Our Excel Formulas and Functions class covers the 30 that matter most — live, hands-on, taught by professionals in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class