While performing repetitive works on a large scale, you may need to substitute multiple characters or values at a time. This tutorial takes a deeper look at how to substitute multiple characters in excel based on their location with another based on content. We will apply several functions and Visual Basic Application code to achieve this task.
Download Practice Workbook
Download this practice workbook to exercise while you are reading this article.
6 Suitable Ways to Substitute Multiple Characters
1. Use the SUBSTITUTE Function to Substitute Multiple Characters
In Excel, the SUBSTITUTE Function substitutes one or more instances of a specified character or text string with another character (s). In the below screenshot, here is a data set of Microsoft Word versions names. For an instance, we want to substitute “Word” with “Excel”. We will apply the SUBSTITUTE Function to have it done.
The syntax of the Excel SUBSTITUTE Function is as follows:
SUBSTITUTE(text, old_text, new_text, [instance_num])
Text – the original text in which you’d like to make changes.
Old_text – the characters you’d want to substitute off.
New_text – the new characters to use in place of old text
Instance_num – the incidence of the old text that you’d like to replace If this parameter is left blank, every instance of the old text will be replaced with the new content.
For instance, all of the formulas below substitute “1” with “2” in cell B5, but the results vary based on the number you provide in the last argument:
a) =SUBSTITUTE(B5, “Word”, “Excel”, 1) – Replaces the first incidence of “Word” with “Excel“.
b) =SUBSTITUTE(B5, “Word”, “Excel”, 2) – Replaces the second incidence of “Word” with “Excel“.
c) =SUBSTITUTE(B5, “Word”, “Excel”) – Replaces all incidences of “Word” with “Excel“.
In the below screenshot, we have shown the example for the first occurrence. To do so, simply follow the steps.
- Type the following formula in cell,
- Press Enter to see the results.
- Repeat the previous steps for the other two criteria.
As a result, you will obtain values for first, second, and all occurrences consecutively to substitute multiple characters in excel.
2. Nest the SUBSTITUTE Function to Substitute Multiple Characters
To do multiple substitutions, within a single formula, you can nest multiple SUBSTITUTE Functions.
Let’s say you have a text value like “art., amend., cl.” in cell B5, where “art.” stands for “article”, “amend.” stands for “amendment” and “cl. ” means “clause“.
What you want is to substitute the three codes with full names. You may accomplish this by using three separate SUBSTITUTE formulae.
Then nest them one inside the other.
To have it done, follow the steps below.
- In cell C5, type the following formula.
- Then, press Enter to see the change.
- Copy the formula in the other required cells.
Therefore, you will see the substituted values shown in the screenshot below.
3. Perform the SUBSTITUTE Function with INDEX Function to Substitute Multiple Characters
In addition to the previous methods, you can also use the SUBSTITUTE Function with the INDEX Function to substitute multiple characters.
For example, you want to substitute red and blue with green and white consecutively. Multiple SUBSTITUTE Functions can be nested, and the INDEX function can be used to feed in find/replace pairs from another table.
To substitute multiple characters applying both the SUBSTITUTE and the INDEX Function follow the steps below.
- Firstly, enter the following formula in cell C5,
INDEX find range is E5:E6
INDEX find range is E5:E6
- Then, Hit Enter to see the results.
- Finally, Copy the formula for other cells.
- Find And Replace Multiple Values in Excel (6 Quick Methods)
- How to Replace Special Characters in Excel (6 Ways)
- Replace Text of a Cell Based on Condition in Excel (5 Methods)
4. Apply the REPLACE Function to Substitute Multiple Characters
In the following section, we will describe how to apply the REPLACE Function to substitute multiple characters in excel. The REPLACE Function in Excel allows you to swap one or several characters in a text string with another character or a set of characters.
The syntax of the Excel REPLACE Function is as follows:
REPLACE(old_text, start_num, num_chars, new_text)
As you see, the REPLACE Function has 4 arguments, all of which are compulsory.
Old_text – the original text (or a reference to a cell with the original text) in which you want to substitute some characters.
Start_num – the position of the first character within old_text.
Num_chars – the number of characters you want to replace.
New_text – the replacement text.
For example, to substitute the word “Face” for “Fact“, you can follow these steps below.
- Firstly, in cell D5, enter the following formula,
=REPLACE(B5, 4, 1,"t")
- Then, press Enter to see the change.
- To make all the changes shown in the below screenshot, copy the formulas for the required cells.
5. Nest the REPLACE Function to Substitute Multiple Character
Quite often, it’s probable that you’ll need to change multiple items in the same cell. Of course, you could perform one replacement, output an intermediate result into a new column, and then use the REPLACE Function once more. However, using nested REPLACE Functions, which allow you to do several replacements with a single formula, is a better and more professional option. Similar to the SUBSTITUTE Function, you can also apply nest in the REPLACE Function.
Let’s say you have a list of phone numbers in column A that are formatted like “123-456-789” and you want to add space to make them look another way. To put it another way, you want to change “123-456-789” to “123 456 789“.
To Substitute the multiple characters in multiple places, follow the steps below.
- Type the following formula in cell C5 at first,
=REPLACE(REPLACE(B5,4,1," "),8,1," ")
- Secondly, press Enter to see the change in cell D5.
- Finally, copy the formula and repeat the steps for the required cells.
6. Run A VBA Code to Substitute Multiple Character
Interestingly, you can apply VBA code to obtain the same to substitute multiple characters. In addition, you can change it as you want without concerning the character number or place as seen in the two previously described functions.
To run a VBA code to substitute multiple characters, just follow the steps described below.
- Firstly, press Alt + F11 to open the Macro-Enabled Worksheet.
- Go to the Insert tab.
- Then, select Module.
- Copy the following VBA code,
Sub replaceAll() 'declare object variable to hold reference to cell you work with Dim myCell As Range 'declare variables to hold parameters for string replacement (string to replace and replacement string) Dim myStringToReplace As String Dim myReplacementString As String 'identify cell you work with Set myCell = ThisWorkbook.Worksheets("VBA").Range("C5") 'specify parameters for string replacement (string to replace and replacement string) myStringToReplace = "234-235-5689" myReplacementString = "234 235 5689" 'replace all occurrences within string in cell you work with, and assign resulting string to Range. 'Value property of cell you work with myCell.Value = Replace(Expression:=myCell.Value, Find:=myStringToReplace, Replace:=myReplacementString) End Sub
ThisWorkbook.Worksheets(“your current worksheet name”)
Range(“your reference cell”)
myStringToReplace = “value you want to substitute”
myReplacementString = “your substituted value”
- Then, paste it into the program window
- Press Enter to see the substituted number format.
To conclude, I hope this article has provided detailed guidance to substitute multiple characters in Excel. All of these procedures should be learned and applied to your dataset. Take a look at the practice workbook and put these skills to the test. We’re motivated to keep making tutorials like this because of your valuable support.
If you have any questions – Feel free to ask us. Also, feel free to leave comments in the section below.
We, The Exceldemy Team, are always responsive to your queries.
Stay with us & keep learning.