#How to Substitute Text in Google Sheets
Table of Contents
“How to Substitute Text in Google Sheets”
Important to managing data is updating it if things change. When you’re working with a text string in Google Sheets, you have a few ways to substitute that text without manually changing the string.
Along with the built-in Find and Replace tool in Google Sheets, you can use a function to substitute text in your spreadsheet, and there’s more than one to get the job done. Let’s take a look at your options for replacing text in your sheet.
Use Find and Replace in Google Sheets
If you’re uncomfortable using functions and formulas, this first option is for you. With Find and Replace, you can search for and substitute text easily. This is also a good option if you want to replace the same text throughout your entire workbook rather than just one sheet.
RELATED: How to Find Data in Google Sheets with VLOOKUP
Open Edit in the menu and select “Find and Replace.”
When the dialog box appears, enter the text you want to replace in the Find field and the new text you want in the Replace With field.
Next to Search, use the drop-down box to select where you want to find and replace. You can choose All Sheets, This Sheet, or Specific Range.
Optionally, mark the boxes for the additional options at the bottom. For example, you can mark Match Case if you want to find all instances of smiTH and replace them with Smith.
If you want to review each case before you replace the text, click “Find” and then “Replace.” To substitute all text immediately, click “Replace All.”
Use the SUBSTITUTE Function
RELATED: Functions vs. Formulas in Microsoft Excel: What’s the Difference?
The syntax for the function is SUBSTITUTE(current_text, find, new_text, occurrence)
where the first three arguments are required. You can use the fourth argument to specify which occurrence in the string to change if there’s more than one.
Select the cell where you want to add the formula and the updated text. In this example, we’ll make a simple change from Jane Doe in cell A1 to Jane Wilson.
=SUBSTITUTE(A1,"Doe","Wilson")
As another example, we want to substitute only a small portion of the text in cell A1. Using this formula, you can change “Iphone” to “iPhone”:
=SUBSTITUTE(A1,"Ip","iP")
To show how to use the optional occurrence
argument, we want to change 2022 to 2023 in cell A1. The argument uses the numbered occurrence in our string which is 3. That means that we’ll change the third number 2 that the function finds.
=SUBSTITUTE(A1,"2","3",3)
To reiterate, A1
is the cell with the text, 2
is the character to replace, 3
in quotes is the character to replace with, and the last 3
is the occurrence.
Use the REPLACE Function
Another way to substitute text in Google Sheets is using the REPLACE function. Using this option, you can replace part of a text string with another based on the position and length to replace.
RELATED: How to Find a Value’s Position With MATCH in Microsoft Excel
The syntax is REPLACE(current_text, position, length, new_text)
where only the first three arguments are required, but you’ll want to use them all.
In this example, we want to replace the ID- at the beginning of our order number with ON- in cell E2.
=REPLACE(E2,1,2,"ON")
The 1
in our formula represents which position the first character we want to replace is in the string and the 2
represents the length of the characters to replace.
As another example, we want to replace a portion in the middle of our string in cell A1. Using this formula, you can replace “New Iphone Case” with “New iPhone 13 Case”.
=REPLACE(A1,5,6,"iPhone 13")
Here we were able to replace the uppercase “I” in “Iphone” with lowercase and add 13
, all in the middle of our text string. The 5
is the position of the first character and the 6
is the length of the string to replace.
Use the REGEXREPLACE Function
One more function you can use to substitute text in Google Sheets is REGEXREPLACE. This is the ideal option for those familiar with using regular expressions. Google uses RE2 expressions and offers help with a syntax list.
RELATED: How to Use Regular Expressions (regexes) on Linux
The syntax for the function is REGEXREPLACE(current_text, regular_expression, new_text)
where the arguments are required.
In this example, we’ll replace our order number in cell A1 using the following formula:
=REGEXREPLACE(A1,"[0-9]+","111111")
Here, the [0-9]+
represents numbers and is placed within quotes and the 111111
is the new text.
For one more example using REGEXREPLACE, we’re replacing the spaces in our product number with hyphens.
=REGEXREPLACE(A1,"\s","-")
Here, the \s
is the regular expression for the spaces. Then we replace those with hyphens (-
).
When you need to substitute new text for old, you have more than one way to do it in Google Sheets. Use whichever works best for you!
RELATED: How to Remove Extra Spaces in Your Google Sheets Data
If you liked the article, do not forget to share it with your friends. Follow us on Google News too, click on the star and choose us from your favorites.
For forums sites go to Forum.BuradaBiliyorum.Com
If you want to read more like this article, you can visit our Technology category.