Excel function

REPLACEfunction

Replaces a number of characters at a given position with other text.

All versions
=REPLACE("555-123-4567", 5, 3, "***")

Text12 chars

15
25
35
4-
51
62
73
8-
94
105
116
127

Result12 chars

15
25
35
4-
5*
6*
7*
8-
94
105
116
127

Drag across the text strip to choose what to replace. Set num_chars to 0 to insert instead. Try breaking it on purpose to see the errors.

Result

555-***-4567

old_text

The original text to change.

start_num

The position of the first character to replace. The first character is 1.

num_chars

How many characters to remove. 0 removes nothing and inserts.

new_text

The text to put in place of the removed characters.

What is the REPLACE function?

=REPLACE(old_text, start_num, num_chars, new_text)

REPLACE removes a number of characters from a given position in a text and puts new text in their place.

Where SUBSTITUTE finds and replaces specific characters, REPLACE works by position: "from the nth character, this many characters". Drag across the strip above to choose the part to replace.

Arguments

old_text
The original text to change.
start_num
The position to start replacing. The first character is 1.
num_chars
How many characters to remove. 0 only inserts.
new_text
The text to put in place of the removed characters.

REPLACE examples

  1. Example 1. Mask a phone number

    =REPLACE("555-123-4567", 5, 3, "***")

    "555-***-4567".

  2. Example 2. Example from Microsoft

    =REPLACE("abcdefghijk", 6, 5, "*")

    Replaces 5 characters from the 6th with *: "abcde*k".

  3. Example 3. Insert characters

    =REPLACE("20261118", 5, 0, "-")

    num_chars is 0, so the result is "2026-1118".

Common mistakes

FAQ

What if start_num is past the end?
new_text is added at the end.
Is there a byte-based version?
Yes, REPLACEB counts bytes in some languages.