RIGHTB function
Returns the last characters of a text up to a given number of bytes; CJK 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
RIGHTB(text, [num_bytes])| Argument | What it means | |
|---|---|---|
text | Required | The text or cell. |
num_bytes | Optional | How many bytes to return from the end. Default 1. |
Returns: Text: the trailing characters that fit into num_bytes.
How RIGHTB works
RIGHTB is the byte-counting version of RIGHT. In the legacy double-byte character sets used for Japanese, Chinese and Korean, each kanji, kana or hangul character takes 2 bytes, while Latin letters and digits take 1. When a file layout or system limit is expressed in bytes, RIGHTB extracts the right amount of text from the end of a value.
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.
Like the other B functions, it cannot return half a character: if the byte count would split a double-byte character, the result is adjusted.
Examples
1Last two kanji of an address (Japanese default language)
| A | B | |
|---|---|---|
| 1 | Address | |
| 2 | 東京都港区 | 港区 |
Result: 港区
Four bytes from the end hold two double-byte characters.
2Mixed text (Japanese default language)
| A | B | |
|---|---|---|
| 1 | Code | |
| 2 | 東京ABC | 京ABC |
Result: 京ABC
ABC gives 3 bytes and 京 the other 2. RIGHT(A2,5) would return the whole text.
3English default language
| A | B | |
|---|---|---|
| 1 | Address | |
| 2 | 東京都港区 | 京都港区 |
Result: 京都港区
Without a DBCS default language each character is 1 byte, so the last 4 characters are returned, just like RIGHT.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#VALUE! | num_bytes is negative. | Use 0 or a positive number. |
Tips
- Combine with LENB to drop a fixed number of bytes from the start:
=RIGHTB(A2,LENB(A2)-6). - For everyday text work use RIGHT, which behaves the same on every computer.
Google Sheets
RIGHTB also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.
RIGHTB 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.