
Replaces part of a text string based on character position.
The Excel REPLACE function changes part of a text string based on character position. You tell Excel where to start, how many characters to replace, and what text to insert instead.
That makes REPLACE different from SUBSTITUTE. SUBSTITUTE looks for matching text content, while REPLACE works by position. If you know the exact part of the string to overwrite, REPLACE is usually the better choice.
Overwrites a section of text based on where it starts and how long it is.
Returns the full string with one section replaced.
=REPLACE(old_text, start_num, num_chars, new_text)
old_text is the original string. start_num is the first character position to replace. num_chars is how many characters to remove. new_text is what you want to insert in their place.
REPLACE and SUBSTITUTE both modify text, but they solve different problems. Use REPLACE when you know the position. Use SUBSTITUTE when you know the text you want to change.
| Function | Targets By | Use When |
|---|---|---|
REPLACE |
Character position | You know where the change starts |
SUBSTITUTE |
Text content | You know what text to replace |
FIND |
- | You need to calculate the replacement position |
REPLACE is useful for masking values, updating fixed parts of a code, or inserting text at a known point. If the same segment always appears in the same position, the formula can stay simple and direct.
REPLACE also has two helpful patterns. If new_text is an empty string, the selected characters are deleted. If num_chars is 0, REPLACE inserts text without removing anything.
If the year always starts in the same place, REPLACE can update it with a fixed position and length. There is no need to search for the year text itself.
=REPLACE(A2, 7, 4, "2024")
// "Excel-2021" -> "Excel-2024"
In cell F1, use REPLACE to change "2021" to "2024" in A2 ("Excel-2021"). The year starts at position 7 and is 4 characters long.
REPLACE is often used to hide part of an ID or account number. The original data remains untouched in the source cell, while the formula returns a safer display version.
=REPLACE(A3, 1, 3, "***")
// "123-456" -> "***-456"
In cell F2, use REPLACE on A3 ("123-456") to replace the first 3 characters with "***".
If the prefix length is known, REPLACE can swap it out directly. This works well when a code format changes but the rest of the string should stay as it is.
=REPLACE(A2, 1, 2, "ID")
// Replaces the first 2 characters with "ID"
In cell F3, use REPLACE on A2 to change the prefix to "ID". The prefix is the first 2 characters.
When the text before the target section may vary in length, use FIND to calculate the start position first. That makes the replacement dynamic instead of hardcoded.
=REPLACE(A2, FIND("-",A2)+1, 4, "XXXX")
// "Excel-2021" -> "Excel-XXXX"
In cell F4, use FIND to locate the hyphen in A2, then use REPLACE to mask the 4 characters after it.
REPLACE always returns text. If the source value is numeric, Excel first treats it as text for the replacement. That matters if the result needs to be used in later calculations.
REPLACE changes text based on character position.=REPLACE(old_text, start_num, num_chars, new_text).Tell your friends about this post