REPLACE Function
Replaces characters at a given position with new text.
Category
Text
Available in
All versions, Microsoft 365
Returns
Text
Overview
REPLACE swaps out characters by position: start here, remove this many, put this in instead.
Use it when you know where the change goes. When you know what to change, use SUBSTITUTE.
Syntax
=REPLACE(old_text, start_num, num_chars, new_text) Explain
Arguments
| Argument | Required? | What it does |
|---|---|---|
| old_text | Yes | The original text. |
| start_num | Yes | Position of the first character to replace. |
| num_chars | Yes | How many characters to remove. 0 inserts without removing. |
| new_text | Yes | The text to put in. |
Examples
Example 1 — Masking account numbers
Hide four digits in the middle of each account number.
B2fx=REPLACE(A2, 6, 4, "****")
| A | B | |
|---|---|---|
| 1 | Account | Masked |
| 2 | ACCT-55120934 | ACCT-****0934 |
| 3 | ACCT-88013377 | ACCT-****3377 |
=REPLACE(A2, 6, 4, "****") Explain
Example 2 — Inserting a character
Turn 20260412 into 2026-0412 by inserting a dash after the fourth character.
=REPLACE(A2, 5, 0, "-") Explain
Common mistakes
- Variable lengths. If the text varies in length, compute start_num with FIND or LEN rather than typing a fixed number.
Notes
- Related functions: SUBSTITUTE, MID, REGEXREPLACE.

Author
Kyle Stott
Certified Microsoft Excel Expert
Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.