Google Sheets Tips

SUBSTITUTE function in Google Sheets: replace text, the nth occurrence and multiple values

SUBSTITUTE replaces every occurrence of a text inside a cell with another text, or only the occurrence you number. This guide works every example on an ad spend export whose channel names are spelled eight ways: the syntax, removing characters, substituting multiple values with nested formulas or a lookup table, counting occurrences, the difference from REPLACE and REGEXREPLACE, and the behaviours that surprise: it is case-sensitive, has no wildcards and always returns text.

Google Sheets TipsVadym Kramarenko10 min read

SUBSTITUTE function in Google Sheets: replace text, the nth occurrence and multiple values

SUBSTITUTE replaces a text inside a cell with another text:

=SUBSTITUTE(B2, "_", " ")

Every underscore in B2 becomes a space, so brand_search_US reads “brand search US”. A fourth argument limits the replacement to one occurrence: =SUBSTITUTE(B2, "_", " ", 1) changes only the first underscore.

Every example below works on one export and one question a marketing lead asks before the weekly budget call: why does the channel report show eight channels when we run three? It is a spelling problem, and SUBSTITUTE fixes inconsistent channel names in one pass. Until it does, the channel that looks cheapest may only be the one whose rows went missing.

The export has ten campaign rows from November 2026, in rows 2 to 11:

Column Holds
A Week
B Campaign (utm_campaign), such as brand_search_US
C Channel as typed: Paid_Search, Paid Search, Paid search, Paid Social, paid social, Paid_Social, E-mail, Email
D Spend
E Revenue

Reading to get this done?

SUBSTITUTE syntax

SUBSTITUTE syntax

=SUBSTITUTE(text_to_search, search_for, replace_with, [occurrence_number])

  • text_to_search: the text, or the cell that holds it.
  • search_for: the text to find. It is matched exactly, with its case.
  • replace_with: the text to put in its place. An empty text, "", removes what was found.
  • occurrence_number: optional. Which occurrence to replace: 1 for the first, 2 for the second. Without it, all are replaced.

=SUBSTITUTE("Paid_Social", "_", " ")

The formula returns “Paid Social”. With a cell reference, the formula can be filled down a column. Rows that do not contain the text come back unchanged:

=SUBSTITUTE(C2, "_", " ")

Google Sheets with the ad spend export and =SUBSTITUTE(C2, “_”, “ “) filled down column F: Paid_Search and Paid_Social lose their underscores, paid social, Paid search and E-mail stay as they are

Two spellings, on three rows, are fixed, and six labels are left where there were eight. Paid search, paid social and E-mail are still their own lines: the next sections deal with them.

What SUBSTITUTE does and does not do

What SUBSTITUTE does and does not do

All of the following comes from our test sheet.

  • It is case-sensitive. =SUBSTITUTE("Email email", "email", "x") returns “Email x”. This is why “paid social” survives a formula written for “Paid Social”.
  • It has no wildcards and no regular expressions. An asterisk, a question mark and a dot are ordinary characters: =SUBSTITUTE("a*b", "*", "-") returns “a-b”. Nothing needs escaping.
  • A text that is not found is not an error. The original comes back unchanged. The same happens when the occurrence number is larger than the number of occurrences.
  • It always returns text. =SUBSTITUTE(1500, "5", "9") returns “1900” as a text, which SUM ignores. Wrap the result in VALUE to calculate with it.
  • On a date it works on what the cell displays, in its number format. With 1/5/2023 in B3, =SUBSTITUTE(B3, "2023", "24") returned the text “1/5/24”.
  • Matches do not overlap. =SUBSTITUTE("aaa", "aa", "b") returns “ba”.

Hand this to your AI

Swapping a list of old values for new ones means nesting SUBSTITUTE again and again, until no one can read the formula.

Paste this into your AI assistant. It writes one formula that applies every pair from a lookup table across your column, instead of a chain of nested SUBSTITUTE calls.

The prompt

replace old values with new ones across a column in my sheet, using a table of pairs instead of nested SUBSTITUTE formulas, and show the rows where nothing matched

Replace or remove text

Replace or remove text

Replace every occurrence

=SUBSTITUTE(B2, "_", " ")

brand_search_US becomes “brand search US”: each underscore becomes one space.

Replace only the first occurrence

=SUBSTITUTE(B2, "_", " ", 1)

The result is “brand search_US”: the first underscore is gone and the one before the market code is kept.

Replace the second occurrence

=SUBSTITUTE(B2, "_", "|", 2)

The result is “brand_search|US”. Only the second underscore changes, marking where the market code starts.

Replace a phrase

The text to find can be several words; replacing words works like replacing characters:

=SUBSTITUTE(C5, "paid social", "Paid Social")

C5 holds “paid social” and comes back as “Paid Social”. Because the match keeps its case, nothing else in the column is touched.

Remove characters

Replace with an empty text. =SUBSTITUTE(C8, "-", "") turns E-mail into “Email”. Each SUBSTITUTE removes one character, so several are nested. Spend that arrives as text, “$1,240”, loses its dollar sign and comma like this:

=SUBSTITUTE(SUBSTITUTE("$1,240", "$", ""), ",", "")

The result is the text “1240”. The same nesting removes the parentheses from a phone number: =SUBSTITUTE(SUBSTITUTE("(555) 0142", "(", ""), ")", "") returns “555 0142”.

To remove any character of a set in one step, REGEXREPLACE is shorter: =REGEXREPLACE("$1,240", "[$, ]", "") removes dollar signs, commas and spaces at once.

To turn a text such as “1,240 USD” into a number, remove the unit and convert: =VALUE(SUBSTITUTE("1,240 USD", " USD", "")).

A whole column from one formula

=ARRAYFORMULA(SUBSTITUTE(C2:C11, "_", " "))

One formula in F2 returns the same column as the filled-down version above. On IDs kept in another tab, =ARRAYFORMULA(SUBSTITUTE(IDs!A2:A9, "OLD-", "NEW-")) turns OLD-101 into NEW-101. See array formulas.

Substitute multiple values

Substitute multiple values

A few values: nest the formulas

Each SUBSTITUTE works on the result of the one inside it:

=SUBSTITUTE(SUBSTITUTE(C2, "_", " "), "E-mail", "Email")

Paid_Search in C2 becomes “Paid Search”, and E-mail in C8 becomes “Email”. The order matters when one replacement produces a text that the next one looks for.

Many values: a table of pairs

Keep the pairs in a table, what to find in one column and the replacement in the next, and let REDUCE apply them one after another. Here H2:I6 holds an underscore to a single space, E-mail to Email, paid to Paid, search to Search, social to Social.

=REDUCE(C2, SEQUENCE(ROWS($H$2:$H$6)), LAMBDA(acc, i, SUBSTITUTE(acc, INDEX($H$2:$H$6, i), INDEX($I$2:$I$6, i))))

REDUCE starts with the text in C2 and runs SUBSTITUTE once for every row of the table, each time on the result of the previous step. Filled down column F, it turns the eight spellings into three channels: Paid Search, Paid Social and Email. A new pair is a new row in the table; the formula stays as it is.

Google Sheets with five find-and-replace pairs in H2:I6 and a REDUCE formula with SUBSTITUTE filled down column F, returning only Paid Search, Paid Social and Email

When the whole cell is the value

If the cell contains nothing but the value to translate, Paid_Search to Paid Search, this is a lookup, not a substitution: =VLOOKUP(C2, $N$2:$O$7, 2, FALSE), with each spelling in N and the agreed name in O. VLOOKUP ignores case, so six rows cover all eight spellings. See VLOOKUP.

SUBSTITUTE with other functions

SUBSTITUTE with other functions

Ignore the case

Change the case of the text first, if the result may be all upper or lower case:

=SUBSTITUTE(LOWER(C2), "paid social", "Paid Social")

Paid Social and paid social both come back as “Paid Social”. The other rows come back in lower case: Paid Search in C3 returns “paid search”.

To keep the rest of the text as it was, use REGEXREPLACE with the case-insensitive flag: =REGEXREPLACE("paid social", "(?i)paid social", "Paid Social") returns “Paid Social”.

Count how many times a text occurs

Remove the text and compare the lengths:

=(LEN(B2) - LEN(SUBSTITUTE(B2, "_", ""))) / LEN("_")

For brand_search_US the formula returns 2; for BF_teaser_meta_DE it returns 3, and for newsletter_nov 1. Filled down, it shows which campaign names have more or fewer parts than the naming scheme expects. See LEN.

Line breaks and invisible spaces

Characters that cannot be typed are given by their code with CHAR: =SUBSTITUTE(C3, CHAR(10), " ") turns line breaks into spaces, and =SUBSTITUTE(C3, CHAR(160), " ") turns non-breaking spaces into ordinary ones, which TRIM can then remove.

Where this shows up in a report: spend by channel

Where this shows up in a report: spend by channel

One formula in F2 fixes the whole channel column in one pass:

=ARRAYFORMULA(PROPER(SUBSTITUTE(SUBSTITUTE(LOWER(C2:C11), "_", " "), "e-mail", "email")))

LOWER removes the case differences, the two SUBSTITUTEs remove the underscores and the hyphen, and PROPER puts the capitals back. =COUNTA(UNIQUE(C2:C11)) returns 8; on column F, 3.

Google Sheets with the one-pass ARRAYFORMULA in F2 returning Paid Search, Paid Social or Email for all ten rows, and a count of 8 labels in column C and 3 in column F

Spend by channel is then =SUMIF($F$2:$F$11, H2, $D$2:$D$11) in J2, filled down. On the raw column C, SUMIF ignores case but still misses the underscores and the hyphen. ROAS is revenue divided by spend:

Channel Spend on raw labels Spend Revenue ROAS
Paid Search $2,790 $5,420 $15,150 2.80
Paid Social $3,550 $4,490 $10,810 2.41
Email $120 $270 $4,780 17.70

On the raw labels, $3,720 of the $10,180 spent is missing from the three lines, $2,630 of it Paid Search, and search and social look level on ROAS: 2.71 against 2.65. On the agreed names it is 2.80 against 2.41, a different conversation about next week’s budget.

Google Sheets with a summary block where =SUMIF($F$2:$F$11, H3, $D$2:$D$11) returns $4,490 for Paid Social against $3,550 on the raw labels, and total spend of $10,180

The decision to write next to the number: the report uses three channel names, Paid Search, Paid Social and Email, and a new spelling is added to the formula before the report goes out. One catch: PROPER turns TikTok into “Tiktok”, so such names belong in a lookup table.

SUBSTITUTE, REPLACE or REGEXREPLACE

SUBSTITUTE, REPLACE or REGEXREPLACE

Finds the text by Use it when
SUBSTITUTE What it is You know the text to replace
REPLACE Position and length You know where it is: characters 4 to 6
REGEXREPLACE A pattern You know its shape: any digits, anything in brackets

To change the values in place, without a formula column, use Find and replace.

Problems and fixes

Problems and fixes

When the result looks wrong, it is usually one of these.

⚠️ Problem: Nothing is replaced.

✅ Solution: The text was not found. Check the case, and check for a space or an invisible character inside the cell; a non-breaking space looks like a space and does not match one.

⚠️ Problem: Numbers no longer add up.

✅ Solution: The result is text. Wrap it in VALUE.

⚠️ Problem: #VALUE!

✅ Solution: The occurrence number is negative. Use 1 or more, or leave it out.

⚠️ Problem: Too much is replaced: renaming “Search” to “Organic Search” also turns “Paid Search” into “Paid Organic Search”.

✅ Solution: SUBSTITUTE has no notion of a word or of a whole cell. When the cell holds only the label, use a lookup or =IF(C2="Search", "Organic Search", C2); for a pattern, use REGEXREPLACE with anchors: "^Search$" matches only a cell that is exactly Search.

⚠️ Problem: #REF! from an ARRAYFORMULA.

✅ Solution: The result has no room to expand. Clear the cells below the formula.

⚠️ Problem: #ERROR! after pasting a formula.

✅ Solution: The quotation marks are curly. Retype them as straight quotes.

Related Google Sheets functions

A replacement table in a sheet is a mapping that belongs to the data

A replacement table in a sheet is a mapping that belongs to the data

Old IDs to new ones, campaign names to channels, eight spellings to three: a table of replacements applied by formulas is a business rule kept in one spreadsheet. The formula is exact; the rows it runs on may not be. The next report needs the same rule and gets a copy of it, and the copies drift apart as soon as one of them gets a new row.

The OWOX Data Marts extension for Google Sheets covers that half. A data analyst publishes a Data Mart (a table or an SQL query in your data warehouse, with the channel names the team agreed) and makes it available for reports. In Sheets you open the extension, pick the Data Mart, tick the columns you want and run it. The rows land in a tab, ready for your formulas.

Google Sheets with the OWOX Data Marts extension open beside an ad spend table: the Unified Ad Spend Data Mart, nine of fourteen columns ticked and a Save & Run button – the rows in the sheet come from a governed Data Mart, not a pasted export

What changes for the person who maintains the sheet:

  • Refresh replaces re-export. Refresh current report in the extension menu re-runs the same pull, and a scheduled refresh keeps the tab current without anyone touching it.
  • The source is written on the sheet. The header cell of an imported tab carries a note with the Data Mart it came from, the time of the import and a link to the report.
  • No SQL and no data warehouse access needed. The analyst decides which Data Marts and columns are available. You choose from that list.

The extension does not write or change the analyst’s SQL. When the mapping is applied once in that SQL, every report built on the Data Mart shows the same channel names, and SUBSTITUTE is left for one-off fixes in a sheet. The extension comes with the OWOX Cloud plans of OWOX Data Marts; spreadsheet reporting describes both ways data reaches a sheet.

Hand this to your AI

Swapping a list of old values for new ones means nesting SUBSTITUTE again and again, until no one can read the formula.

Paste this into your AI assistant. It writes one formula that applies every pair from a lookup table across your column, instead of a chain of nested SUBSTITUTE calls.

The prompt

replace old values with new ones across a column in my sheet, using a table of pairs instead of nested SUBSTITUTE formulas, and show the rows where nothing matched

FAQ

Frequently Asked Questions

Can I use SUBSTITUTE and REPLACE together in the same formula?

Yes. One can work on the result of the other. On the campaign name brand_search_US in B2, `=REPLACE(SUBSTITUTE(B2, "_", " "), 1, 5, "Brand")` first turns every underscore into a space, giving "brand search US", and then REPLACE puts "Brand" over the first five characters, returning "Brand search US". SUBSTITUTE finds the text by what it is, REPLACE by where it sits, so together they handle a name that has both a wrong character and a wrong prefix.

Can I use SUBSTITUTE to remove text in Google Sheets?

Yes. Replace the text with an empty text, "". For a channel label typed as E-mail, `=SUBSTITUTE(C8, "-", "")` returns "Email", so it lands on the same line as the rows already spelled Email. Each SUBSTITUTE removes one text, so to remove two characters, such as the dollar sign and the comma in "$1,240", nest one SUBSTITUTE inside another. The result is always text; wrap it in VALUE to calculate with it.

What’s the difference between REPLACE and SUBSTITUTE in Google Sheets?

SUBSTITUTE finds the text by what it is, REPLACE by its position and length. To fix the channel label Paid_Search, `=SUBSTITUTE(C2, "_", " ")` replaces every underscore wherever it is and returns "Paid Search". REPLACE needs to be told where to look: `=REPLACE(C2, 5, 1, " ")` changes the fifth character only. Use SUBSTITUTE when you know the text to change and REPLACE when you know where it sits.

Is SUBSTITUTE case-sensitive?

Yes. SUBSTITUTE matches the text with its case: `=SUBSTITUTE("Email email", "email", "x")` returns "Email x". In a channel column that holds both Paid Social and paid social, a formula written for one spelling leaves the other as it is. To fix both, change the case first, `=PROPER(LOWER(C5))`, or use REGEXREPLACE with the (?i) flag, which ignores case and keeps the rest of the text as it was.

Can SUBSTITUTE be used to replace only specific occurrences of text?

Yes. The optional fourth argument, the occurrence number, picks which one to replace. On the campaign name brand_search_US, `=SUBSTITUTE(B2, "_", " ", 1)` changes only the first underscore and returns "brand search_US", while `=SUBSTITUTE(B2, "_", "|", 2)` changes only the second and returns "brand_search|US". Without the fourth argument every occurrence is replaced. If the number is larger than the number of occurrences, the text comes back unchanged.

How do I use the SUBSTITUTE function in Google Sheets?

Give it the text or cell, the text to find and the replacement: `=SUBSTITUTE(C2, "_", " ")` turns the channel label Paid_Search into "Paid Search". Filled down a column, it fixes every label with an underscore and leaves the others unchanged. A fourth argument, the occurrence number, replaces only that occurrence. Nest several SUBSTITUTE formulas, or apply a table of pairs with REDUCE, to fix more than one spelling at once. The result is always text.

What is the SUBSTITUTE function in Google Sheets?

SUBSTITUTE replaces one text inside a cell with another, every occurrence or only the one you number. Its everyday use is cleaning labels before they reach a report. In an ad spend export where one channel is typed as Paid_Social, Paid Social and paid social, a SUMIF on the raw labels misses the underscore spelling; after one formula with SUBSTITUTE, all three land on one Paid Social line. It is case-sensitive and has no wildcards.

Who wrote this

Vadym Kramarenko

Vadym Kramarenko Growth Marketing Manager

Vadym Kramarenko is a Growth Marketing Manager at OWOX, where he drives user acquisition and product-led growth strategies. He hosts the OWOX podcast, interviewing analytics professionals about data-driven marketing, attribution, and reporting best practices. Vadym specializes in turning complex analytics concepts into practical, actionable marketing frameworks.