REPLACEB Function

Excel Functions › Text

All Excel versions DBCS languages

The Excel REPLACEB function overwrites part of a text string, with the target region defined by a starting byte and a length in bytes. It is the byte-counting twin of REPLACE, built for double-byte character set (DBCS) languages — Japanese, Chinese, and Korean — where each native character occupies 2 bytes when such a language is the system default. Working in English or any other single-byte language? REPLACEB behaves exactly like REPLACE — just use REPLACE.


Quick answer: to overwrite 4 bytes starting at byte 5 of A2 with new text:
=REPLACEB(A2, 5, 4, "2027") // bytes 5-8 replaced
The replacement text can be any length — only the removed region is measured in bytes.

Syntax

=REPLACEB(old_text, start_num, num_bytes, new_text)
ArgumentDescription
old_textRequiredThe original string.
start_numRequiredThe byte position where replacement begins. The first byte is 1.
num_bytesRequiredHow many bytes to remove before inserting new_text.
new_textRequiredThe text to insert. Its own length is irrelevant — it can be shorter, longer, or empty.

Available in: all Excel versions. Byte counting activates only when a DBCS language (Japanese, Chinese Simplified/Traditional, or Korean) is the system default language; otherwise positions and lengths are in characters and REPLACEB matches REPLACE exactly. Positions usually come from FINDB or SEARCHB.

REPLACEB vs REPLACE: byte-defined surgery

On a Japanese-locale system, 東京2026 spans 8 bytes — the kanji occupy bytes 1–4 and the year occupies bytes 5–8. Byte coordinates drive the edits:

ABC
1Text in A2: 東京2026FormulaResult (Japanese locale)
2byte positions: 東=1–2, 京=3–4, 2026=5–8=REPLACEB(A2, 5, 4, "2027")東京2027
3=REPLACEB(A2, 1, 4, "大阪")大阪2026
4=REPLACEB("Dallas", 1, 3, "Au")Aulas — same as REPLACE
=REPLACEB(A2, 5, 4, "2027") // swap the year - bytes 5-8
=REPLACEB(A2, 1, 4, "大阪") // swap the city - bytes 1-4

Updating a byte-defined field inside a fixed-width record is the bread-and-butter case — the file spec says “bytes 11–14”, and REPLACEB speaks that language:

=REPLACEB(A2, 11, 4, "0000") // zero out the 4-byte field at bytes 11-14

Pair with FINDB when the position must be discovered rather than known:

=REPLACEB(A2, FINDB("-", A2), 1, "/") // replace the first hyphen, byte-safely

Try it: byte-replacement sandbox

Live demo

Pick the byte region to overwrite and the replacement text, and toggle the system locale to see how byte counting changes the cut.

Errors & common pitfalls

Pitfall: results depend on the system language. =REPLACEB(A2, 5, 4, ...) targets different text on a Japanese-locale machine than on a US-locale one — the byte grid moves underneath the formula. In shared workbooks, byte-based edits are a portability trap; note the assumption or use REPLACE.

Working in English? Use REPLACE. On single-byte locales REPLACEB adds nothing over REPLACE. And if you want to replace specific text rather than a position, you want SUBSTITUTE in the first place.

Pitfall: slicing a character in half. If start_num or the byte count cuts into the middle of a 2-byte character, the surviving half becomes a space in the result. Keep DBCS edits on even boundaries — or anchor them with FINDB so they start on a real character.

#VALUE! — bad coordinates. start_num must be at least 1 and num_bytes zero or more. Arithmetic like FINDB(...) - 2 drifting below 1 is the usual cause; clamp with MAX where positions are computed.

Practice workbook

📊
Download the free REPLACEB practice workbook
Every example on this page, ready to open in Excel — plus practice challenges with answers on a separate tab. No sign-up required.

Frequently asked questions

What's the difference between REPLACEB and REPLACE?
REPLACE measures the region to overwrite in characters; REPLACEB measures it in bytes. They differ only when a DBCS language (Japanese, Chinese, Korean) is the system default — then each East Asian character spans 2 byte positions, so the same coordinates target different text.
What's the difference between REPLACEB and SUBSTITUTE?
REPLACEB overwrites a region defined by position (in bytes); SUBSTITUTE replaces occurrences of specific text, wherever they appear, with no positions involved. “Replace bytes 5–8” is REPLACEB; “replace every hyphen with a slash” is SUBSTITUTE.
Why does REPLACEB give me the same answer as REPLACE?
Your system default language isn’t a DBCS language, so every character counts as one byte and the two functions coincide. Expected behaviour — use REPLACE.
Does new_text have to fit the byte count I removed?
No. num_bytes only sizes the hole; new_text can be longer, shorter, or empty. =REPLACEB(A2, 5, 4, "") deletes bytes 5–8 outright, and inserting without removing is num_bytes = 0.

Master functions like this in one day

This page covers one function. Our Excel Formulas and Functions class covers the 30 that matter most — live, hands-on, taught by professionals in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related functions: REPLACE · SUBSTITUTE · FINDB · MIDB · LENB