Quick Answer

REPLACE Function

Replaces characters by position.

✓ Excel✓ Google SheetsExcel All versions

Syntax

REPLACE
(old_text, start_num, num_chars, new_text)

Parameters

ParameterDescriptionRequired
old_textThe original text or cell reference containing the text to modify.Required
start_numThe character position (1-based) at which to begin replacing.Required
num_charsThe number of characters in old_text to replace with new_text.Required
new_textThe text that replaces the specified characters.Required

Basic Example

Replace the middle of a string

=REPLACE("abcdef",2,3,"XYZ")
ResultaXYZef

Starting at position 2, three characters ("bcd") are replaced by "XYZ".

Advanced Examples

Example 1: Mask part of an account number

Cell A1 holds "1234567890"

Hide the middle digits

=REPLACE(A1,4,4,"****")
Result: 123****890
Characters 4 through 7 are replaced with asterisks for a masked display.

Example 2: Insert text without removing any

Add a dash after the first two characters of A1 = "AB1234"

Use num_chars of 0 to insert

=REPLACE(A1,3,0,"-")
Result: AB-1234
With num_chars set to 0, new_text is inserted at the position without deleting anything.

How REPLACE Works

REPLACE identifies characters by position. It deletes num_chars characters beginning at start_num and inserts new_text in their place, then returns the rebuilt string.

1
Find the position
Note the 1-based index where the change begins.
2
Count characters
Decide how many characters to replace.
3
Write REPLACE
Enter =REPLACE(old, start, count, new) and press Enter.

Important Notes & Limitations

  • Replacement is positional, so it does not search for matching text the way SUBSTITUTE does.

  • If start_num is beyond the text length the result may be unchanged or appended depending on version.

  • Doubles as an insertion tool only when num_chars is 0.

Common Errors & Fixes

#VALUE! errorstart_num is less than 1 or num_chars is negative.

Fix: Use a start_num of at least 1 and a non-negative num_chars.

Wrong characters changedOff-by-one in start_num or miscounting num_chars.

Fix: Remember positions are 1-based and count carefully.

Download Practice File

Practice REPLACE with Real Data

Download a sample CSV file with pre-populated data and practice exercises for the REPLACE function. Works in both Excel and Google Sheets.

Works in Google SheetsCompatible with ExcelIncludes exercises

File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps

Frequently Asked Questions

REPLACE vs SUBSTITUTE?
REPLACE changes characters by position; SUBSTITUTE replaces specific text you search for.
Can REPLACE insert text?
Yes, set num_chars to 0 and new_text is inserted at start_num.
Is the first character position 1?
Yes, positions in REPLACE are 1-based.