Back to functions
Text2026-06-130 related articles

REPLACE Function in Excel

Replace part of a text string by character position and length.

Syntax

REPLACE(old_text, start_num, num_chars, new_text)

Arguments

old_text

Required

The original text that contains the characters you want to replace.

start_num

Required

The character position where Excel should start replacing text.

num_chars

Required

The number of characters Excel should remove from the original text.

new_text

Required

The new text Excel should insert in place of the removed characters.

What it returns

Returns the updated text after replacing characters at the chosen position.

What REPLACE does

REPLACE swaps out characters based on where they sit in the text string. It is useful when the part you want to change always appears in the same position, such as fixed-width imports, account masks, or code formatting.

Practical examples

Replace the first three characters

=REPLACE(A2,1,3,"SKU")

If A2 starts with an old prefix, this formula swaps that prefix for SKU.

Mask part of an ID

=REPLACE(A2,5,4,"XXXX")

This is useful when you want to hide part of a value while keeping the rest visible.

Common mistakes and notes

REPLACE works by position

If the target text does not always start in the same place, SUBSTITUTE is usually safer because it matches the text itself.

start_num counts from 1

Excel text positions start at 1, not 0. Off-by-one mistakes are the most common reason for wrong output.

num_chars controls removal length

If you remove too few or too many characters, the formula still runs but returns the wrong text. Double-check the width of the piece you want to replace.

Related functions

Official documentation