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
| Argument | Type | Required | What it does |
|---|---|---|---|
text | string | yes | The text to change. A number is treated as text. |
position | number | yes | Where the replacement starts, counted from 1. |
length | number | yes | How many characters to remove. 0 inserts without removing. |
new_text | string | yes | The text put in place of the removed part. |
Examples
The examples use this table, starting in A1:
| Code | Note |
| RO-2024-001 | draft |
| Hello World | greeting |
=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.