The REPLACE function swaps a section of a text value with another text value. Its output is always a value of type text. The location of the section is defined with the start_num and num_chars arguments. The start_num argument defines the position of the leftmost character of the section to be swapped, and the num_chars argument defines the total number of characters the section contains. Use the SUBSTITUTE function if it isn’t possible to define the location of the section.
Invocations of the REPLACE function take the form:
REPLACE(old_text,start_num,num_chars,new_text)
Example
Consider a cell containing the formula:
=REPLACE("Gray car", 2, 3, "reen")
The formula instructs the REPLACE function to swap the section of the text value “Gray car“, 3 characters in length and starting at character 2, with the text value “reen“. Characters 2 to 4 inclusive of “Gray car” form the text value “ray” and the REPLACE function returns “Green car“. The process is illustrated below:
Its purpose is identical to that of the REPLACE function: the SUBSTITUTE function swaps a section of a text value with another text value. SUBSTITUTE differs from REPLACE in that:
only the sequence of characters to be swapped needs to passed to it, not its location.
if a sequence of characters occurs ≥ 1 times in a text value, it can swap each of them.