Going Stellar

Home/Google Sheets reference

Google Sheets function · Text

REPLACE in Google Sheets: syntax and examples

REPLACE works by position, not by content. You give the start and the number of characters to remove, and it puts new text in their place. To replace a known word wherever it appears, use SUBSTITUTE.

Syntax

REPLACE(text, position, length, new_text)

Arguments

ArgumentTypeRequiredWhat it does
textstringyesThe text to change. A number is treated as text.
positionnumberyesWhere the replacement starts, counted from 1.
lengthnumberyesHow many characters to remove. 0 inserts without removing.
new_textstringyesThe text put in place of the removed part.

Examples

The examples use this table, starting in A1:

CodeNote
RO-2024-001draft
Hello Worldgreeting
=REPLACE(A2, 4, 4, "2025")

Result: RO-2025-001

Four characters starting at position 4 (the year) are swapped for 2025.

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

=REPLACE(A3, 1, 5, "Howdy")

Result: Howdy World

The first five characters of Hello World become Howdy.

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

=REPLACE(A3, 6, 0, " big")

Result: Hello big World

A length of 0 inserts text at position 6 and removes nothing.

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

=REPLACE(A3, 7, 100, "Sheets")

Result: Hello Sheets

A length longer than the rest of the text just replaces everything from the position onward.

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

=REPLACE(12345, 2, 2, "X")

Result: 1X45

A number is read as text: 1, then X, then 45.

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

Common errors

  • Position 0 returns #VALUE!. Counting starts at 1.
  • A negative length returns #VALUE!. Use 0 to insert without removing.
  • REPLACE changes one fixed stretch of text. It does not look for a word. Use SUBSTITUTE for that, or REGEXREPLACE for patterns.
  • The result is always text, even when the input was a number, so wrap it in VALUE before doing math.

Compared with Excel

Same syntax as Excel REPLACE.

Sources

  1. REPLACE (Docs Editors Help)

Markdown version · All functions