0
0
Google Sheetsspreadsheet~15 mins

SUBSTITUTE and REPLACE in Google Sheets - Deep Dive

Choose your learning style9 modes available
Overview - SUBSTITUTE and REPLACE
What is it?
SUBSTITUTE and REPLACE are two functions in Google Sheets used to change text inside cells. SUBSTITUTE replaces specific text you choose with new text, while REPLACE changes part of the text based on position and length. Both help you fix or update text without retyping everything.
Why it matters
These functions save time and reduce errors when editing text in spreadsheets. Without them, you would have to manually find and change text, which is slow and prone to mistakes. They make data cleaning and updating easier, especially with large lists or repeated patterns.
Where it fits
Before learning SUBSTITUTE and REPLACE, you should know basic text handling in spreadsheets like entering text and simple formulas. After mastering these, you can learn more advanced text functions like REGEXREPLACE or combining text functions for complex data cleaning.
Mental Model
Core Idea
SUBSTITUTE swaps specific words or phrases you name, while REPLACE changes text by counting characters from a position.
Think of it like...
Think of SUBSTITUTE like swapping out a specific word in a sentence with another word, like changing 'cat' to 'dog' wherever it appears. REPLACE is like cutting out a piece of a sentence starting at a certain letter and pasting in new words there.
Text: "I love apples"

SUBSTITUTE("I love apples", "apples", "oranges") → "I love oranges"

REPLACE("I love apples", 8, 6, "oranges") → "I love oranges"

Explanation:
SUBSTITUTE finds "apples" and swaps it.
REPLACE starts at character 8, removes 6 characters, inserts "oranges".
Build-Up - 8 Steps
1
FoundationUnderstanding Basic Text in Cells
🤔
Concept: Learn how text is stored and displayed in spreadsheet cells.
Text in cells is a sequence of characters like letters, numbers, or symbols. You can type words or sentences directly into cells. Formulas can read and change this text.
Result
You can see and edit text in cells, ready for formulas to work on.
Knowing that text is just characters in order helps you understand how functions can find and change parts of it.
2
FoundationUsing Simple Text Replacement Manually
🤔
Concept: Practice changing text by hand to see what needs automating.
Try typing a sentence like "I like cats" in a cell. Then change "cats" to "dogs" manually. Notice how this is easy for one cell but slow for many.
Result
You understand the need for automatic text replacement.
Manual editing is slow and error-prone, so functions like SUBSTITUTE and REPLACE are valuable.
3
IntermediateSUBSTITUTE Function Basics
🤔Before reading on: do you think SUBSTITUTE changes text by position or by matching words? Commit to your answer.
Concept: SUBSTITUTE replaces all or some occurrences of a specific text string with new text.
Syntax: SUBSTITUTE(text, old_text, new_text, [instance_num]) - text: original text - old_text: text to replace - new_text: replacement text - instance_num (optional): which occurrence to replace Example: =SUBSTITUTE("apple, apple, apple", "apple", "orange", 2) Replaces only the 2nd 'apple' with 'orange'.
Result
"apple, orange, apple"
SUBSTITUTE lets you target specific words or phrases, not just positions, making it flexible for text edits.
4
IntermediateREPLACE Function Basics
🤔Before reading on: does REPLACE work by matching words or by counting characters? Commit to your answer.
Concept: REPLACE changes text by removing a number of characters starting at a position and inserting new text there.
Syntax: REPLACE(original_text, start_num, num_chars, new_text) - original_text: text to change - start_num: position to start replacing (1 = first character) - num_chars: how many characters to remove - new_text: text to insert Example: =REPLACE("I love cats", 8, 4, "dogs") Removes 4 characters starting at position 8 and inserts 'dogs'.
Result
"I love dogs"
REPLACE is precise for changing text by position, useful when you know exactly where the change should happen.
5
IntermediateComparing SUBSTITUTE and REPLACE
🤔Before reading on: which function would you use to replace the 3rd occurrence of a word? Which to replace characters at position 5? Commit to your answers.
Concept: Understand when to use SUBSTITUTE versus REPLACE based on text matching or position.
SUBSTITUTE changes text by matching words or phrases, optionally targeting a specific occurrence. REPLACE changes text by position and length, ignoring the actual text content. Example: Text: "red, blue, red, green" - SUBSTITUTE to change 2nd 'red' to 'yellow' - REPLACE to change characters starting at position 6 =SUBSTITUTE(A1, "red", "yellow", 2) =REPLACE(A1, 6, 4, "purple")
Result
SUBSTITUTE result: "red, blue, yellow, green" REPLACE result: "red, purple, red, green"
Knowing the difference helps pick the right tool: SUBSTITUTE for word-based changes, REPLACE for position-based edits.
6
AdvancedUsing SUBSTITUTE with Optional Instance Number
🤔Before reading on: do you think leaving out the instance number replaces all or just the first occurrence? Commit to your answer.
Concept: Learn how SUBSTITUTE replaces all occurrences by default or a specific one if instance number is given.
If you omit the instance_num, SUBSTITUTE replaces every match. Example: =SUBSTITUTE("cat, cat, cat", "cat", "dog") Result: "dog, dog, dog" If you specify instance_num, only that occurrence changes. Example: =SUBSTITUTE("cat, cat, cat", "cat", "dog", 2) Result: "cat, dog, cat"
Result
Flexible control over how many replacements happen.
Understanding this prevents accidental full replacements when only one change is needed.
7
AdvancedCombining REPLACE and LEN for Dynamic Changes
🤔Before reading on: can you use LEN inside REPLACE to replace the last few characters? Commit to your answer.
Concept: Use LEN to find text length and REPLACE to change text dynamically based on length.
Example: Replace last 3 characters with 'XYZ' =REPLACE(A1, LEN(A1)-2, 3, "XYZ") If A1 is "Hello123", result is "HelloXYZ". This works because LEN(A1) gives total length, so LEN(A1)-2 is start of last 3 chars.
Result
Dynamic text replacement based on text length.
Combining functions lets you handle text changes even when length varies, making formulas more powerful.
8
ExpertHandling Nested SUBSTITUTE and REPLACE for Complex Edits
🤔Before reading on: do you think nesting SUBSTITUTE inside REPLACE or vice versa can solve multi-step text edits? Commit to your answer.
Concept: Learn to nest SUBSTITUTE and REPLACE to perform multiple text changes in one formula.
Example: Replace 2nd 'cat' with 'dog' and then replace characters at position 1-3 with 'The' =REPLACE(SUBSTITUTE(A1, "cat", "dog", 2), 1, 3, "The") If A1 is "cat, cat, cat", result is "The, dog, cat". Nesting lets you chain changes without extra columns.
Result
Multiple text edits done in one formula efficiently.
Mastering nesting unlocks complex text transformations without manual steps or helper columns.
Under the Hood
SUBSTITUTE scans the text left to right, finds matches of the old_text, and replaces either all or a specified occurrence with new_text. REPLACE counts characters from the start, removes a set number, and inserts new_text at that position. Both return a new text string without changing the original cell content.
Why designed this way?
SUBSTITUTE was designed to target text by content because users often want to fix or update specific words. REPLACE was designed for precise edits when position matters, like changing fixed-format codes. Separating these allows simpler, clearer formulas and better performance.
Original Text
   │
   ├─> SUBSTITUTE: Find 'old_text' → Replace with 'new_text' (all or nth occurrence)
   │
   └─> REPLACE: Count characters → Remove 'num_chars' → Insert 'new_text' at position

Resulting Text
Myth Busters - 4 Common Misconceptions
Quick: Does SUBSTITUTE replace text based on position or matching words? Commit to your answer.
Common Belief:SUBSTITUTE replaces text by position like REPLACE does.
Tap to reveal reality
Reality:SUBSTITUTE replaces text by matching the exact word or phrase, not by position.
Why it matters:Using SUBSTITUTE expecting position-based replacement leads to wrong text changes and confusion.
Quick: If you omit the instance number in SUBSTITUTE, does it replace only the first or all occurrences? Commit to your answer.
Common Belief:SUBSTITUTE replaces only the first occurrence by default.
Tap to reveal reality
Reality:SUBSTITUTE replaces all occurrences if instance number is omitted.
Why it matters:This can cause unintended mass replacements, corrupting data if you wanted to change only one instance.
Quick: Can REPLACE be used to replace text by matching words? Commit to your answer.
Common Belief:REPLACE can find and replace specific words anywhere in the text.
Tap to reveal reality
Reality:REPLACE only works by position and length, not by matching text content.
Why it matters:Trying to use REPLACE for word-based changes causes errors or wrong replacements.
Quick: Does nesting SUBSTITUTE inside REPLACE always work as expected? Commit to your answer.
Common Belief:Nesting SUBSTITUTE and REPLACE is straightforward and always reliable.
Tap to reveal reality
Reality:Nesting can cause unexpected results if you don't carefully manage order and parameters.
Why it matters:Misunderstanding nesting leads to complex bugs and hard-to-debug formulas.
Expert Zone
1
SUBSTITUTE is case-sensitive, so 'Apple' and 'apple' are different; this subtlety affects replacements.
2
REPLACE counts characters including spaces and punctuation, so invisible characters can shift positions unexpectedly.
3
Using SUBSTITUTE with instance_num greater than the number of occurrences returns the original text unchanged, which can be used to test presence.
When NOT to use
Avoid SUBSTITUTE and REPLACE when you need pattern matching or complex text extraction; use REGEXREPLACE or REGEXEXTRACT instead for flexible, pattern-based text manipulation.
Production Patterns
Professionals often combine SUBSTITUTE with ARRAYFORMULA to clean entire columns of data at once. REPLACE is used in formatting codes or IDs where fixed positions must be changed, such as updating area codes in phone numbers.
Connections
Regular Expressions (Regex)
SUBSTITUTE and REPLACE are simpler text replacement tools compared to regex-based functions.
Understanding SUBSTITUTE and REPLACE builds a foundation for learning regex functions, which handle more complex text patterns.
String Manipulation in Programming
These functions mirror string replace methods in programming languages like Python or JavaScript.
Knowing spreadsheet text functions helps grasp similar concepts in coding, making cross-tool learning easier.
Editing Text in Word Processors
SUBSTITUTE is like 'Find and Replace' in word processors, while REPLACE is like manually cutting and pasting text at a position.
Recognizing this connection helps users transfer their text editing skills from documents to spreadsheets.
Common Pitfalls
#1Replacing text without specifying instance number when only one occurrence should change.
Wrong approach:=SUBSTITUTE(A1, "cat", "dog")
Correct approach:=SUBSTITUTE(A1, "cat", "dog", 1)
Root cause:Not knowing SUBSTITUTE replaces all occurrences by default leads to unintended multiple replacements.
#2Using REPLACE with wrong start position causing wrong text to be replaced.
Wrong approach:=REPLACE(A1, 5, 3, "dog")
Correct approach:=REPLACE(A1, 8, 3, "dog")
Root cause:Miscounting character positions or forgetting spaces and punctuation shifts the replacement area.
#3Trying to replace text by matching words using REPLACE instead of SUBSTITUTE.
Wrong approach:=REPLACE(A1, FIND("cat", A1), LEN("cat"), "dog")
Correct approach:=SUBSTITUTE(A1, "cat", "dog")
Root cause:Confusing REPLACE's position-based method with SUBSTITUTE's content-based replacement.
Key Takeaways
SUBSTITUTE replaces specific words or phrases by matching text, optionally targeting a single occurrence.
REPLACE changes text by position and length, useful when you know exactly where to edit.
Omitting the instance number in SUBSTITUTE replaces all matches, which can cause unintended changes.
Combining SUBSTITUTE and REPLACE with other functions like LEN allows dynamic and powerful text edits.
Understanding when to use each function prevents common mistakes and unlocks efficient text manipulation in spreadsheets.