This article describes the formula syntax and usage of the REPLACE function in Microsoft Excel.
Description
REPLACE replaces part of a text string, based on the number of characters you specify, with a different text string.
Syntax
REPLACE(old_text, start_num, num_chars, new_text)
The REPLACE function syntax has the following arguments:
-
Old_text Required. Text in which you want to replace some characters.
-
Start_num Required. The position of the character in old_text that you want to replace with new_text.
-
Num_chars Required. The number of characters in old_text that you want REPLACE to replace with new_text.
-
New_text Required. The text that will replace characters in old_text.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel worksheet. For formulas to show results, select them, press F2, and then press Enter. If you need to, you can adjust the column widths to see all the data.
Data |
||
---|---|---|
abcdefghijk |
||
2009 |
||
123456 |
||
Formula |
Description (Result) |
Result |
=REPLACE(A2,6,5,"*") |
Replaces five characters in abcdefghijk with a single * character, starting with the sixth character (f). |
abcde*k |
=REPLACE(A3,3,2,"10") |
Replaces the last two digits (09) of 2009 with 10. |
2010 |
=REPLACE(A4,1,3,"@") |
Replaces the first three characters of 123456 with a single @ character. |
@456 |
Important:
-
The REPLACEB function is deprecated.
-
In workbooks set to Compatibility Version 2, REPLACE has improved behavior with Surrogate Pairs, counting them as one character instead of two. Variation Selectors (commonly used with emojis) will still be counted as separate characters. Read more here: The Unicode standard