Excel - SUBSTITUTE Function



SUBSTITUTE Function

The Excel SUBSTITUTE function interchanges the existing substring in an input string with a new substring. It is categorized as a part of the EXCEL TEXT function and was first introduced in the Excel version 2007. An error may arise if the negative value is provided in its third argument. For example, using the SUBSTITUTE function, you can transform integer numbers into words, remove text wrapping, and merge different field values with a delimiter.

Compatibility

This advanced Excel function is compatible with the following versions of MS-Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web
  • Excel 2024
  • Excel 2024 for Mac
  • Excel 2021
  • Excel 2021 for Mac
  • Excel 2019
  • Excel 2016
  • Excel 2013
  • Excel 2010
  • Excel 2007

Syntax

The syntax of the SUBSTITUTE function is as follows −

SUBSTITUTE (text, old_text, new_text, [instance_num])

Arguments

You can use the following arguments with the SUBSTITUTE function −

Argument Description Required / Optional
Text It specifies a text or the cell reference that points to a text string in which the specific characters to be substituted. Required
Old_text It denotes the text for modification. Required
New_text It specifies the text interchanging with Old_text Required
Instance_num A positive number specifies the occurrence of the Old_text in the text. If skipped, all the Old_text's instances will be replaced by the New_text. Optional

Points To Remember

  • If the Old_text is not found in the Text, then the SUBSTITUTE function will return the exact input string.
  • If the Instance_num contains a negative value, the SUBSTITUTE function returns the #VALUE! Error.
  • If the Instance_num is skipped, then all occurrence of the old_text is interchanged with the new_text.
  • It is case-sensitive, and wild cards are incompatible with this function.

Examples of SUBSTITUTE Function

Practice the following examples to learn the use of the SUBSTITUTE function in Excel.

Example 1: Replacing Substrings with SUBSTITUTE Function

The SUBSTITUTE function in Excel allows you to replace specific text within a string with new text.

Solution

Step 1 − First, the sample dataset consists of four columns: Text, Old Text, New Text, Instance, and Result.

How to Replace Substring Using SUBSTITUTE

Step 2 − After that, select the =SUBSTITUTE(C2,D2,E2) in the G2 cell and hit the Enter tab.

Select =SUBSTITUTE(C2,D2,E2) in G2 cell

Therefore, the SUBSTITUTE function will substitute the "Functions" substring with the "Tutorial" in the input Text and return the "Excel Tutorial" as a result.

SUBSTITUTE Function Will Substitute Functions

Step 3 − Moreover, move to the downward cell G3, write the formula =SUBSTITUTE(C3,D3,E3,F3). In this expression, only the first occurrence of the old_text will be replaced with the new_text.

Old Text will be Replaced with New Text

Therefore, the result is "Software Developer Project Engineer".

Software Developer Project Engineer

Step 4 − Furthermore, select the G4 cell, enter the formula =SUBSTITUTE(C4,D4,E4,F4), and press the Enter tab.

Enter Formula SUBSTITUTE in G4 Cell

Hence, the SUBSTITUTE function will interchange the second occurrence of the Engineer with the "Developer" in the given text.

SUBSTITUTE Function Will Interchange

Example 2: Remove Word Wrapping in Excel

Let's say the text wrapping is shown in the B2 cell and write the formula =SUBSTITUTE(B2,CHAR(10),"") in the C2 cell.

How to Remove Word Wrapping in Excel

Hit the Enter tab to get the result.

Remove Word Wrapping Result

Example 3: Using Nested SUBSTITUTE Function to Convert Whole Numbers Into Words

The nesting multiple SUBSTITUTE functions, you can convert whole numbers into their word equivalents.

Solution

In this example, we will transform the random number into words. Select the C3 cell and write the formula =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B3,5,"Five hundred"),4," forty "),7,"seven"). In this expression, 5 is replaced by "five hundred", 4 is replaced by "forty", and 7 is interchanged by seven.

7 is Interchanged by Seven

Therefore, the result is Five hundred forty seven.

Result is Five Hundred Forty Seven

Download Practice Sheet

You can download and use the sample data sheet to practice the SUBSTITUTE function.

Advertisements