Let’s first grasp what a Substitute Function is and when to use it. Before we figure out how to use the SUBSTITUTE function.
What is a Substitute function?
A Substitute is a person or a thing acting or serving in place of another.
Substitute function replaces/swaps a set of characters with another in a text string.
For example, you can instruct the computer to substitute ‘and’ for ‘&’. Now, your instructions have to be clear if not the computer could interpret ‘Ander’ for say ‘&er’.
When can we use Substitute function?
You use the SUBSTITUTE function when you want to replace specific text in a text string. This differentiates it from REPLACE function. You use REPLACE when you want to replace any text that occurs in a specific location in a text string.
We will talk more about REPLACE function in our next article.
The Computer Language called SYNTAX
The instruction given to the computer while on the excel platform is called the SYNTAX. This command is:
=SUBSTITUTE(text, old_text, new_text, [instance_number])
For example, you can tell the computer to substitute ‘and’ for ‘&’. Now, your instructions have to be clear if not the computer could interpret ‘Ander’ for say ‘&er’.
Note that the SUBSTITUTE function is case sensitive. (Take a look at the highlighted words above). Though the instructions were the same, the results were different. The reason for this was the use of Capita “A” in the second case.
Let’s say you have made your monthly report of sales made in October 2011. As shown in the diagram above. And you want to use a similar data for October 2016 monthly report.
You want to substitute: Sold for Bought; Toys for Cars; No for Number and 2016 for 2011
Step 1: Copy the above data in a new spreadsheet.
Take note of the Column and Rows.
Step 2: Fill in the Column Headings (Formula, Description, Result).
Step 3: Under the result column, type in your instructions:
In Cell E2: =SUBSTITUTE(B2, “Bought”, “Sold”)
Cell E3: =SUBSTITUTE(B3, “Cars”, “Toys”)
Cell E4: =SUBSTITUTE(B4, “o”, “umber”, 1)
Cell E5: =SUBSTITUTE(B6, “1”, “6”, 2)
Note: Start with “=“ and there is no space between SUBSTITUTE and the bracket open sign
If done, your result column will look like the one in the picture above.
Step 4: Let’s write out the instruction again so we can very much remember it. This time we will write it under the Formula column. Type in
Cell C2: =SUBSTITUTE(B3, “Bought”, “Sold”)
Cell C3: =SUBSTITUTE(B4, “Cars”, “Toys”)
Cell C4: =SUBSTITUTE(B5, “o”, “umber”, 1)
Cell C5: =SUBSTITUTE(B6, “1”, “6”, 2)
Note: Start with a “Spacebar”.
Step 5: Also for clearer understanding, let us give a description of the formula we used. So under the Description column, type in
Cell D2: Substitutes Sold for Bought
Cell D3: Substitutes Toys for Cars
Cell D4: Substitutes first instance of “o” with “number”
Cell D5: Substitutes second instance of “1” with “6”
Your spreadsheet should look like the picture above.
Step 6: You can now hide any of the columns you don’t want to be displayed. You can always unhide it at any time, most especially for reference purpose.
In our case study, I will hide the Formula and Description columns
First, you select the column/columns you want to hide.
Next, right click on the mouse to bring down the menu
Then, select Hide
It will look the picture above
Note: To unhide, select the columns bounding the hidden column/columns. Right click on the mouse. Then select Unhide in the drop-down menu.
We have succeeded in the used of Substitute Function.