Substitute Function in Google Sheets: A Practical Guide

Learn how to use the SUBSTITUTE function in Google Sheets with practical examples, edge cases, and templates. This guide covers syntax, nesting, arrays, and common pitfalls for everyday data cleaning.

How To Sheets
How To Sheets Team
·5 min read
Quick AnswerDefinition

SUBSTITUTE is the substitute function google sheets that edits strings by swapping a specified old_text with new_text within a given text. It works on single cells or arrays via ARRAYFORMULA. Syntax: SUBSTITUTE(text, old_text, new_text, [instance_num]). Use instance_num to replace only a specific occurrence; omit to replace all.

What SUBSTITUTE does in Google Sheets

SUBSTITUTE is a text function that lets you replace occurrences of a string inside another string. It's ideal when you want to clean data, normalize naming, or reformat text without affecting surrounding characters. In practice, you apply it to a cell like A2 and specify the old substring and the new substring. The function does not alter the original cell; it returns a new string. In Google Sheets, the substitute function google sheets is a common workflow for processing text across ranges; you can wrap this in ARRAYFORMULA to process ranges.

Excel Formula
=SUBSTITUTE(A2, "cat", "dog")

Example:

  • Replacing a single word in a sentence: =SUBSTITUTE("The cat sat on the mat","cat","dog") → "The dog sat on the mat".
  • Processing a range with arrays: =ARRAYFORMULA(SUBSTITUTE(A2:A, "cat", "dog"))

Syntax and core arguments

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

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

Parameters:

  • text: The input text or a reference to a cell
  • old_text: The substring to replace
  • new_text: The replacement string
  • instance_num (optional): If provided, only this occurrence is replaced
Excel Formula
=SUBSTITUTE(A2, "2023", "2024", 3)

Note: You can apply SUBSTITUTE within an ARRAYFORMULA to handle ranges:

Excel Formula
=ARRAYFORMULA(SUBSTITUTE(B2:B, "old", "new"))

Basic examples: simple replacements

Let's see concrete replacements:

Excel Formula
=SUBSTITUTE("pineapple banana pineapple","pineapple","apple")

This replaces all occurrences of "pineapple" with "apple" in the string, yielding "apple banana apple".

Excel Formula
=SUBSTITUTE(A2, "banana", "fruit")

If A2 contains "banana bread", the result is "fruit bread". This demonstrates replacing a word within a sentence. You can also apply it to a range with arrays:

Excel Formula
=ARRAYFORMULA(SUBSTITUTE(A2:A, "banana", "fruit"))

Replacing all occurrences vs. a specific instance

By default, SUBSTITUTE replaces all matching occurrences of old_text within text. To limit to a single occurrence, supply the optional instance_num parameter:

Excel Formula
=SUBSTITUTE("red red red","red","scarlet")

Result: "scarlet scarlet scarlet" (all occurrences replaced).

Excel Formula
=SUBSTITUTE("red red red","red","scarlet",2)

Result: "red scarlet red" (only the 2nd occurrence replaced).

Using SUBSTITUTE with arrays (array formulas)

Array usage extends SUBSTITUTE to entire columns or rows. This is especially useful for cleaning datasets without creating helper columns:

Excel Formula
=ARRAYFORMULA(SUBSTITUTE(A2:A, "old", "new"))

You can combine multiple substitutions in a single formula by nesting or chaining SUBSTITUTE calls within ARRAYFORMULA:

Excel Formula
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(A2:A, "old","new"), "x","y"))

Practical scenarios and tips

Common data-cleaning tasks include replacing separators (like underscores) with spaces and normalizing codes. For example:

Excel Formula
=SUBSTITUTE(A2, "_", " ")

If you need more complex patterns, REGEXREPLACE may be a better fit, but SUBSTITUTE shines for straightforward, exact-text replacements:

Excel Formula
=REGEXREPLACE(A2, "(?i)cat|dog", "pet")

Performance tip: For very large ranges, limit the input to the needed rows to reduce calculation overhead.

Common pitfalls and performance considerations

  • If old_text is not found, SUBSTITUTE returns the input unchanged, which can mask data issues. Always verify your inputs.
  • The function is sensitive to the exact characters; to ignore case, wrap text with LOWER or UPPER.
  • When applying across large ranges, prefer ARRAYFORMULA with careful range limits to avoid sluggish performance.
  • Ensure quotes around strings; numeric literals are treated as numbers, not text, which can yield unexpected results.
Excel Formula
=IF(A2<>"", SUBSTITUTE(A2, "Low", "Low"), "")

These practices help avoid subtle mistakes and keep your sheets responsive.

Nested examples and alternatives

For multiple replacements, you can nest SUBSTITUTE calls to handle several old->new mappings without REGEX. If you need pattern-based changes, REGEXREPLACE can be more flexible, but SUBSTITUTE remains faster for exact text changes in many datasets:

Excel Formula
=SUBSTITUTE(SUBSTITUTE(A2, "old1","new1"), "old2","new2")

Summary of usage and best practices

  • Use SUBSTITUTE for exact text replacements within a string or range.
  • Use ARRAYFORMULA to apply to columns or rows without helper columns.
  • For case-insensitive replacements, wrap text in LOWER/UPPER before substitution.
  • Consider REGEXREPLACE for pattern-based edits; use SUBSTITUTE for straightforward tasks.

Real-world scenarios and performance

In real workbooks, SUBSTITUTE can normalize product codes, fix punctuation, or rebrand items across datasets. When combined with IF or FILTER, you can conditionally apply replacements to specific rows. Always test on a copy of your data before applying to large sheets to avoid unintended edits.

Steps

Estimated time: 15-25 minutes

  1. 1

    Identify target text

    Choose the cell or range where you want to replace text. Decide whether you need to replace all occurrences or a specific one.

    Tip: Sketch a small sample first to confirm behavior.
  2. 2

    Write the SUBSTITUTE formula

    In a new column, enter the SUBSTITUTE formula with text, old_text, and new_text. Include instance_num if needed.

    Tip: Double-check quotes around strings.
  3. 3

    Extend to a range

    If replacing across many rows, wrap the formula in ARRAYFORMULA to cover the entire column.

    Tip: Use an empty header row to keep results tidy.
  4. 4

    Validate results

    Scan results for edge cases where old_text isn't present or case differences exist. Iterate if necessary.

    Tip: Compare a few cells with manual replacements.
Pro Tip: Use ARRAYFORMULA to apply SUBSTITUTE across a whole column.
Warning: Be mindful of the 4th parameter; it targets a single occurrence only.
Note: If old_text is not found, SUBSTITUTE returns the original text.
Pro Tip: For case-insensitive replacements, wrap text with LOWER or UPPER first.

Prerequisites

Required

Optional

  • Optional: sample dataset to experiment
    Optional

Keyboard Shortcuts

ActionShortcut
Open Find and ReplaceIn Google Sheets to search and replace across sheetCtrl+H
Find next matchWhile the Find dialog is openCtrl+G
Apply replacementAccept current replacement in dialog

FAQ

What is the SUBSTITUTE function in Google Sheets?

SUBSTITUTE replaces occurrences of old_text with new_text inside a text string. It can target all occurrences or a specific instance when you provide the optional instance_num. It returns the modified text and does not alter the original cell.

SUBSTITUTE swaps text strings inside a cell, either for all matches or for one specific one.

Is SUBSTITUTE case-sensitive in Google Sheets?

SUBSTITUTE matches the exact characters you specify; if you need a case-insensitive match, normalize the text with LOWER or UPPER.

Yes—it's case-sensitive; to ignore case, normalize text first.

How is SUBSTITUTE different from REPLACE?

SUBSTITUTE replaces a specified substring within text, while REPLACE modifies text by position. SUBSTITUTE uses string matching; REPLACE uses indices.

SUBSTITUTE swaps text; REPLACE changes by position.

Can SUBSTITUTE work on ranges?

Yes. Use ARRAYFORMULA to apply SUBSTITUTE across a column or row.

Absolutely, with ARRAYFORMULA you can cover ranges.

What are common mistakes when using SUBSTITUTE?

Forgetting quotes around strings, misusing instance_num, or not accounting for case differences can cause surprises. Always test on sample data.

Watch out for quotes, instance_num, and case handling.

The Essentials

  • Understand SUBSTITUTE syntax and parameters
  • Use ARRAYFORMULA for range applications
  • Use instance_num to replace a single occurrence
  • Consider case handling with LOWER/UPPER if needed

Related Articles