REPLACE
Replace a run of characters at a known position with different text.
Syntax
REPLACE(old_text, start_num, num_chars, new_text) | Argument | Required | Description |
|---|---|---|
old_text | Required | The text to modify. |
start_num | Required | Where the replacement starts, counting from 1. |
num_chars | Required | How many characters to remove. Zero inserts without removing. |
new_text | Required | What to put there. |
Examples
Every example below was executed against VisiGrid engine 0.31.0 — not
transcribed from another vendor's documentation. Reproduce any of them with vgrid calc.
| Formula | Result | Notes |
|---|---|---|
=REPLACE("abcdef",2,3,"X") | aXef | Three characters from position 2 become one. |
=REPLACE("abcdef",1,0,"X") | Xabcdef | Removing zero characters inserts at the front. |
=REPLACE("héllo",2,1,"e") | hello | Positions count characters, so accents behave. |
Position, not content
That is the entire distinction from SUBSTITUTE:
=REPLACE("abcdef", 2, 3, "X") → aXef by position
=SUBSTITUTE("a-b-c", "-", "+") → a+b+c by content
Use REPLACE when the location is fixed and the content varies — masking all
but the last four digits of an account number, swapping a fixed-width prefix,
blanking a known column of a fixed-format record.
Inserting without deleting
num_chars of 0 inserts rather than replaces, which is how you add a prefix,
a separator, or a check character at a known offset:
=REPLACE(A1, 4, 0, "-") → inserts a hyphen after the third character
Combining with FIND
When the position is not fixed, compute it. FIND or
SEARCH locates the boundary and REPLACE acts on it —
though for replacing content you have found, SUBSTITUTE is usually more
direct.
Excel compatibility
Matches Excel.