Contact

REPLACE Function in Microsoft Excel: Examples, Pitfalls & Compatibility

Text Beginner Microsoft Excel

REPLACE in Microsoft Excel: replace a known character span by position rather than searching for matching words. Includes worked examples and application-specific cautions. Includes historical REPLACEB byte syntax and migration cautions.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: Use REPLACE in Microsoft Excel to replace a known character span by position rather than searching for matching words. The official REPLACE reference is the source for the function definition and platform-specific rules described below.

Availability and version history

  • Introduced: Introduction version not established by the official history reviewed.
  • Availability: Official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2016.
  • Compatibility caution: Unicode handling can depend on workbook Compatibility Version 2. The similarly named byte-counting REPLACEB function is deprecated; that does not mean REPLACE itself is retired.
  • Checked: October 14, 2026; official REPLACE reference. Documentation check, not a new native test; existing example-verification notes retain their scope.

Syntax and arguments

=REPLACE(old_text, start_num, num_chars, new_text)

old_text (required): The original text or a cell containing it.

start_num (required): The starting character position; the first character is position 1.

num_chars (required): How many existing characters to remove.

new_text (required): The replacement text; it can be a different length from the removed span.

Examples use English function names, comma argument separators and decimal points. Adapt formula separators to your workbook settings, not punctuation inside quoted text.

When to use it

Use REPLACE when a file specification gives a fixed position, such as a two-character region prefix. Use SUBSTITUTE when the target is identified by its text instead. Position-based edits are fragile when the incoming format is inconsistent.

Three worked examples

Each example is independent. Where input cells are listed, enter those values first; otherwise the formula is self-contained. Expected outputs are independently checked calculations or documented error expectations, not captured results from Microsoft Excel.

Example 1: Update a fixed two-letter prefix

=REPLACE("AB-314",1,2,"ZX")

Expected result: "ZX-314" (quoted here to make spaces and text boundaries visible).

The first two characters are replaced; the hyphen and numeric suffix remain.

Example 2: Build a display mask

=REPLACE("AB-123456",4,6,"******")

Expected result: "AB-******" (quoted here to make spaces and text boundaries visible).

Six characters beginning after the prefix are replaced with six asterisks. The source remains recoverable if it is still stored elsewhere.

Example 3: Insert a separator without deleting text

=REPLACE("TRK778",4,0,"-")

Expected result: "TRK-778" (quoted here to make spaces and text boundaries visible).

A zero-length removal inserts the new text before the fourth character. The original six characters are retained.

Put it to work safely

Write down the input format and check its length before filling a replacement formula down a column. Store results in a new field and review unexpected lengths. A mask applied in a display column is not secure redaction: the original values can still be present in the workbook or its history. Remove sensitive source data through an appropriate separate process before sharing a file.

Historical REPLACEB: byte contract and migration

Status: Microsoft’s current REPLACE reference explicitly marks REPLACEB as deprecated. This historical section is for understanding and migrating existing formulas, not recommending REPLACEB for new work. Deprecated does not mean a verified removal from a particular build.

First and last versions: The reviewed first-party sources do not establish REPLACEB’s first supported Excel release or its last supported release. The modern REPLACE article’s Applies To list is not a REPLACEB support matrix. No retirement date or removal build is claimed.

REPLACEB syntax and distinct behavior

=REPLACEB(old_text, start_num, num_bytes, new_text)

All four arguments are required. REPLACEB replaces a segment of old_text starting at a one-based byte position; num_bytes is the amount of old text to replace, not a limit on new_text. The Office implementation notes require the start to be at least 1. This is worksheet syntax; the Microsoft Excel function API corroborates the argument order and optionality. Its API-set number is not a worksheet introduction date.

The REPLACEB Office implementation notes document language-sensitive counting: with a DBCS-supporting default language, a double-byte character contributes two bytes and a single-byte character contributes one. Otherwise each character contributes one byte. The documented DBCS languages include Japanese, Simplified Chinese, Traditional Chinese and Korean. This is a distinct historical contract, not merely an alternative spelling of REPLACE.

Reproducible ASCII checks for REPLACEB

Enter these self-contained formulas in separate blank cells in an Excel version that accepts REPLACEB:

=REPLACEB("INV-482",5,3,"731")

Expected: INV-731. Replace the three ASCII digits starting at byte 5.

=REPLACEB("ABCD",2,0,"-")

Expected: A-BCD. Removing zero bytes inserts the hyphen before the second byte.

These results were independently checked using ASCII string operations, not executed in Excel. They do not verify DBCS behavior. No Japanese output is asserted without a directly sourced fixture; the language-dependent and partial-byte cases still require native testing.

Moving an old REPLACEB workbook forward

REPLACEB edits a position, not every occurrence of a matched word. When moving to REPLACE, convert both the start and removal length to character units; do not reuse byte offsets from FINDB or SEARCHB unexamined.

Compatibility Version 2 changes REPLACE to count a Unicode surrogate pair as one character rather than two. Variation selectors and components of combined emoji can still count separately. Before migrating, record the actual Excel build, default language and workbook Compatibility Version. Microsoft identifies Version 2 as available in Microsoft 365; Excel 2024 and earlier are limited to Version 1. Retest the whole formula chain and preserve the original workbook.

Historical-section verification: Microsoft documentation checked October 19, 2026; independent ASCII checks only. No native Excel execution, DBCS test or screenshot is claimed.

Additional historical reference: WorksheetFunction.ReplaceB.

Common mistakes and fixes

The wrong characters were overwritten. Positions start at 1, not 0. Count the separators as characters and confirm the input format.

The result has a different length. The inserted text does not have to match the removed span. This is intentional, so validate the resulting identifier length when a fixed-width format is required.

The same substring occurs in several places. REPLACE does not search for occurrences. Use SUBSTITUTE for a text-based replacement rule.

Microsoft Excel-specific notes

Microsoft documents a Compatibility Version 2 change to surrogate-pair counting in REPLACE. Variation selectors can still be counted separately. Fixed positions in emoji-containing text need testing in the actual workbook compatibility version. See the vendor reference for the current definition.

Excel and Google Sheets comparison

The ASCII examples avoid differences in Unicode character counting. Confirm position boundaries again after converting a workbook that contains emoji, combining marks or other multi-code-unit characters.

Compare the REPLACE guide for Google Sheets and its official documentation. Having a guide in both libraries establishes two documented references, not a certificate of identical behavior across releases, locales or file conversions.

Evidence and testing scope

Editorial verification: Official references retrieved on 2026-10-12. The three worked cases are included in this release’s reproducible Python checking suite. It checks the stated arithmetic, calendar or text model and the expected documented error classification; it is not the Microsoft Excel calculation engine. No native application run, UI screenshot, maximum-size benchmark or cross-version certification is claimed. Review the editorial testing standards before relying on a formula in a critical workbook.