LEFTB function
Returns the first characters of a text up to a given number of bytes; double-byte characters count as 2 when a DBCS language is the default.
Available in All versions of Excel, including Microsoft 365, Excel for Mac and Excel for the web
In every Excel versionWorks in Google Sheets
Syntax
LEFTB(text, [num_bytes])| Argument | What it means | |
|---|---|---|
text | Required | The text or cell. |
num_bytes | Optional | How many bytes to return. Default 1. |
Returns: Text: the leading characters that fit into num_bytes.
How LEFTB works
LEFTB is the byte-based version of LEFT. Instead of counting characters, it counts bytes, which matters for text in Japanese, Chinese or Korean, where each kanji, hanzi or hangul character occupies 2 bytes in the legacy double-byte encodings, while Latin letters and digits use 1. Fixed-width export files for banks or government systems in those countries often specify field widths in bytes, and LEFTB lets you cut text to fit.
Byte counting only happens when a double-byte (DBCS) language - Japanese, Chinese (Simplified or Traditional) or Korean - is set as the default editing language under File > Options > Language. With any other default language every character counts as 1 byte and the B version behaves exactly like the normal one.
If the byte limit would cut a double-byte character in half, Excel does not return half a character; the result can be one byte shorter than requested (sometimes padded with a space). Test your formulas on real data when that matters.
Examples
1First 4 bytes of a Japanese address (Japanese default language)
| A | B | |
|---|---|---|
| 1 | Address | |
| 2 | 東京都港区 | 東京 |
Result: 東京
Each kanji is 2 bytes, so 4 bytes hold exactly two characters.
2Mixed Latin and kanji text (Japanese default language)
| A | B | |
|---|---|---|
| 1 | Code | |
| 2 | ABC東京 | ABC東 |
Result: ABC東
ABC uses 3 bytes and 東 the next 2, so 5 bytes return four characters. LEFT(A2,5) would return the whole text.
3Same address with an English default language
| A | B | |
|---|---|---|
| 1 | Address | |
| 2 | 東京都港区 | 東京都港 |
Result: 東京都港
Without a DBCS default language each character counts as 1 byte, so LEFTB behaves exactly like LEFT and returns 4 characters.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#VALUE! | num_bytes is negative. | Use 0 or a positive number. |
Tips
- Check the byte length of the whole value first with LENB to see whether it needs cutting at all.
- For normal character-based work use LEFT; it gives the same result on every computer.
Google Sheets
LEFTB also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
LEFTB in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.