Text strings are sequences of characters that can represent words, sentences, numbers, or symbols. In Excel, you may often need to manipulate text strings for various purposes, such as changing the case, formatting, or replacing some parts of the text with other text.
In this article, we will focus on how to use the SUBSTITUTE function in Excel to replace specific text in a text string with another text. We will also compare it with the REPLACE function, which can replace any text that occurs in a specific location in a text string.
The SUBSTITUTE function has the following syntax:
=SUBSTITUTE(text, old_text, new_text, [instance_num])
The arguments are:
text
– the original text or a reference to a cell containing text for which you want to substitute characters.old_text
– the text you want to replace.new_text
– the text you want to replaceold_text
with.instance_num
– optional. Specifies which occurrence ofold_text
you want to replace withnew_text
. If you specifyinstance_num
, only that instance ofold_text
is replaced. Otherwise, every occurrence ofold_text
intext
is changed tonew_text
.
The SUBSTITUTE function returns a new text string with the specified substitution.
The REPLACE function has the following syntax:
=REPLACE(old_text, start_num, num_chars, new_text)
The arguments are:
old_text
– the original text or a reference to a cell containing text in which you want to replace some characters.start_num
– the position of the first character withinold_text
that you want to replace.num_chars
– the number of characters you want to replace.new_text
– the replacement text.
The REPLACE function returns a new text string with the specified replacement.
Procedures
To use the SUBSTITUTE function in Excel, follow these steps:
- Select a cell where you want to enter the formula.
- Type
=SUBSTITUTE(
and then select or type thetext
argument. - Type a comma (
,
) and then select or type theold_text
argument. - Type another comma and then select or type the
new_text
argument. - Optionally, type another comma and then select or type the
instance_num
argument. - Type a closing parenthesis (
)
) and press Enter.
To use the REPLACE function in Excel, follow these steps:
- Select a cell where you want to enter the formula.
- Type
=REPLACE(
and then select or type theold_text
argument. - Type a comma and then select or type the
start_num
argument. - Type another comma and then select or type the
num_chars
argument. - Type another comma and then select or type the
new_text
argument. - Type a closing parenthesis and press Enter.
Example
Suppose you have a list of product names in column A, and you want to replace the word “Pro” with “Plus” in the names. You can use the SUBSTITUTE function to do this, as shown in the following table:
Product Name | Formula | Result |
---|---|---|
Laptop Pro | =SUBSTITUTE(A2, “Pro”, “Plus”) | Laptop Plus |
Tablet Pro | =SUBSTITUTE(A3, “Pro”, “Plus”) | Tablet Plus |
Phone Pro | =SUBSTITUTE(A4, “Pro”, “Plus”) | Phone Plus |
Alternatively, you can use the REPLACE function to do the same thing, but you need to specify the position and the number of characters to replace, as shown in the following table:
Product Name | Formula | Result |
---|---|---|
Laptop Pro | =REPLACE(A2, 7, 3, “Plus”) | Laptop Plus |
Tablet Pro | =REPLACE(A3, 7, 3, “Plus”) | Tablet Plus |
Phone Pro | =REPLACE(A4, 6, 3, “Plus”) | Phone Plus |
Note that the REPLACE function requires you to adjust the start_num
argument depending on the length of the product name, while the SUBSTITUTE function does not.