Excel REPLACE Function
REPLACE swaps characters in a text value by starting position and length.
Use it to rewrite fixed-width codes, mask part of an ID, insert a prefix, or update text when the character positions are predictable.
REPLACE syntax & arguments
Syntax
=REPLACE(old_text, start_num, num_chars, new_text)
-
1
old_text
RequiredThe original text value, cell reference, or formula result to edit.
-
2
start_num
RequiredThe character position where replacement should begin.
-
3
num_chars
RequiredHow many characters to remove from
old_textstarting atstart_num. -
4
new_text
RequiredThe text to insert in place of the removed characters.
Example
=REPLACE(A2, 4, 2, "US")
Replace two characters in A2 starting at character 4 with US.
REPLACE caveats
-
Positions start at 1
start_numof1begins at the first character. Astart_numless than 1 returns a#VALUE!error. -
num_chars controls deletion
num_charsis how many old characters are removed beforenew_textis inserted. -
num_chars can be zero
Use
0fornum_charswhen you want to insertnew_textwithout removing any existing characters. Excel inserts it before the character atstart_num, so=REPLACE("abcd", 2, 0, "X")returnsaXbcd. -
REPLACE does not search
Use FIND to calculate a position, or use SUBSTITUTE when matching text should be replaced wherever it appears.
Need delimiter-based edits? Use FIND to calculate start_num when the replacement should begin at a delimiter or marker that can appear in different positions.
Intro REPLACE practice problem
Solve the intro problem directly here, or open it on its own page.
Advanced REPLACE practice problems
Use REPLACE alongside other Excel functions in realistic, less-prescriptive challenges.