Going Stellar

Home/Google Sheets reference

Google Sheets function · Text

SUBSTITUTE in Google Sheets: syntax and examples

SUBSTITUTE swaps one piece of text for another inside a string. It works on matching text, not on positions, so it suits cleaning spaces, dashes and codes. Give an occurrence number to change just one match.

Syntax

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

Arguments

ArgumentTypeRequiredWhat it does
text_to_searchstringyesThe text to change.
search_forstringyesThe piece of text to find. Case matters.
replace_withstringyesThe text that takes its place. An empty string removes the match.
occurrence_numbernumbernoWhich match to replace, counted from 1. Without it, all matches change.

Examples

The examples use this table, starting in A1:

Text
a-b-c-b
Hello World
2026-11-29
Tel: 0722 123 456
=SUBSTITUTE(A2, "-", "/")

Result: a/b/c/b

Every dash becomes a slash.

Run in a Google Sheet (English US locale) on .

=SUBSTITUTE(A2, "b", "X", 2)

Result: a-b-c-X

Only the second b changes.

Run in a Google Sheet (English US locale) on .

=SUBSTITUTE(A4, "-", "")

Result: 20261129

An empty replacement deletes the dashes.

Run in a Google Sheet (English US locale) on .

=SUBSTITUTE(A5, " ", "")

Result: Tel:0722123456

Strip the spaces from a phone number.

Run in a Google Sheet (English US locale) on .

=LEN(A2) - LEN(SUBSTITUTE(A2, "-", ""))

Result: 3

Count how many times a character appears: compare the length before and after removing it.

Run in a Google Sheet (English US locale) on .

=SUBSTITUTE(A3, "world", "Sheets")

Result: Hello World

Lowercase search text does not match World, so nothing changes.

Run in a Google Sheet (English US locale) on .

Common errors

  • The search is case sensitive: "world" does not find World, and the text comes back unchanged without any error.
  • occurrence_number 0 does not mean none: it replaces every match, as if the argument were missing. A number larger than the match count leaves the text as it was.
  • A search text that does not appear gives no error, only unchanged text. Compare the result with the original when you clean a whole column.
  • To change characters by position, not by content, use REPLACE instead.

Compared with Excel

Same syntax and case rules as Excel SUBSTITUTE.

Questions and answers

How do I remove a character from a cell in Google Sheets?

Use SUBSTITUTE with an empty string as the third argument: =SUBSTITUTE(A2, "-", ""). Nest several SUBSTITUTE calls to remove more than one character.

Sources

  1. SUBSTITUTE (Docs Editors Help)

Markdown version · All functions