ID EN
#Text

REPLACE

Excel Functions

Replace text based on location

Syntax

EXCEL
=REPLACE(old_text, start_num, num_chars, new_text)

Arguments

Parameter Description
old_text The text to replace.
start_num The starting location in the text to search.
num_chars The number of characters to replace.
new_text The text to replace old_text with.

Return Value

The altered text.

Details

The REPLACE function replaces text at a specific location inside a text string. The location of the text to replace is given as a number representing the first character to replace, along with a character count to indicate how many characters to replace. Unlike SUBSTITUTE, which replaces text by matching content, REPLACE works by position and character count. REPLACE is ideal in cases where the text to replace can't easily be matched, but the location is predictable. REPLACE function takes four separate arguments in a generic syntax like this: The first argument, old_text, is the text string to be processed. The second argument, start_num, specifies the numeric position where replacement should begin. The third argument, num_chars, indicates how many characters to replace. The final argume

Examples

Example #1 - Basic usage

REPLACE function takes four separate arguments in a generic syntax like this:

EXCEL
=REPLACE(old_text,start_num,num_chars,new_text)
Example #1 - Basic usage

The first argument, old_text, is the text string to be processed. The second argument, start_num, specifies the numeric position where replacement sho

EXCEL
=REPLACE("C:\docs",1,1,"D") // returns "D:\docs"
=REPLACE("ABC123",4,3,"456") // returns "ABC456"
=REPLACE("XYZ",1,1,"") // returns "YZ"
=REPLACE("www.google.com",1,4,"") // returns "google.com"
Example #2 - Replace different text at same location

In the example below, the goal is to replace the year values in the middle of the text strings in column B with the year 2025. This is a scenario wher

EXCEL
=REPLACE(B5,5,4,"2025")
Example #3 - Change first letter

In the worksheet below, the goal is to change the first letter of each path in column B to the letter "Z". This is another good use case for the REPLA

EXCEL
=REPLACE(B5,1,1,"Z")
Example #4 - Remove first characters

The REPLACE function can be used to remove text by providing an empty string ("") for the new_text argument. In the example below, the goal is to stri

EXCEL
=REPLACE(B5,1,4,"")
Example #5 - Conditionally remove text

In the example below, we have the same problem as above, except the www isn't always present. This means we need to check for the presence of these ch

EXCEL
=IF(LEFT(B5,4)="www.",REPLACE(B5,1,4,""),B5)

See Also

SUBSTITUTE FIND REGEXREPLACE