REPLACE Function

Replaces characters at a given position with new text.

Category

Text

Available in

All versions, Microsoft 365

Returns

Text

Taught hands-on in Level 4: Advanced Dynamic Arrays & Logic - Advanced Math & Text module

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

ArgumentRequired?What it does
old_textYesThe original text.
start_numYesPosition of the first character to replace.
num_charsYesHow many characters to remove. 0 inserts without removing.
new_textYesThe 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, "****")
AB
1AccountMasked
2ACCT-55120934ACCT-****0934
3ACCT-88013377ACCT-****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

Kyle Stott

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.