Rightb
RIGHTB Function¶
The RIGHTB function in Excel is a text function that allows users to extract a specified number of bytes from the
end (right side) of a text string. It is the byte-based counterpart of the RIGHT function. In single-byte character
set (SBCS) languages like English, RIGHTB behaves identically to RIGHT. In double-byte character set (DBCS)
languages such as Japanese, Chinese, and Korean, each double-byte character is counted as 2 bytes, making the
distinction important.
Syntax:¶
RIGHTB(text, [num_bytes])
- text: The text string from which you want to extract characters. This can be a direct string, a cell reference, or the result of another function.
- num_bytes (optional): The number of bytes to extract starting from the right side of the string. If omitted, it defaults to 1, meaning only the last byte will be extracted.
Key Details:¶
- If
num_bytesis greater than the byte length of the text string, theRIGHTBfunction will return the entire string without any error. - If
num_bytesis set to 0, the result will be an empty string (""). - If
num_bytesis negative or not an integer, Excel will return a#VALUE!error. - In SBCS languages (e.g., English),
RIGHTBreturns the same results asRIGHTbecause each character equals one byte. The difference only becomes apparent in DBCS languages where characters may occupy two bytes.
Examples:¶
-
Extracting the Last Three Bytes:
This formula will return"cel", which are the last three bytes of the text "Excel" (in an SBCS environment, this is equivalent to the last 3 characters). -
Default Behavior (Extracting the Last Byte):
Sincenum_bytesis omitted, the formula will return"l", the last byte of the text string "Excel". -
Using a Cell Reference: If cell A1 contains the text "Product123", the formula:
will return"123", extracting the last 3 bytes from the value in cell A1. -
Combining with Other Functions: You can use
This formula extracts all bytes after a hyphen ("-") in a string. It calculates the number of bytes to extract based on the byte position of the hyphen.RIGHTBin combination with other functions. For example: -
Handling Too Many Bytes: If you try to extract more bytes than are available in the string, the
will returnRIGHTBfunction will still return the full string. For example:"Excel"even though the text string contains fewer than 10 bytes.
Notes:¶
- The
RIGHTBfunction is case-sensitive and returns the characters exactly as they appear in the text string. - It is commonly used in data parsing tasks involving DBCS text, such as extracting suffixes or parts of product codes where byte positions matter.
- The
num_bytesargument counts bytes, not characters. When working with DBCS text, be mindful that a double-byte character occupies positions for two bytes. - For character-based extraction from the right (rather than byte-based), use the
RIGHTfunction. - The
RIGHTBfunction is equivalent toRIGHTin Excel when the default language setting is a single-byte character set language. In DBCS language environments,RIGHTBcounts each double-byte character as 2 bytes.
By combining RIGHTB with other byte-based functions like LENB and FINDB, you can perform advanced text string
manipulations with ease in DBCS language environments.