RIGHT(), RIGHTB()

Syntax

Definition. The RIGHT() function returns the last characters of a string. The RIGHTB() function is used for double-byte characters and returns the last bytes.

Arguments

Background. Use the RIGHT() function to extract characters from the end of a string (see Figure 8-10). You can enter letters or numbers in the text argument. The functions RIGHT(), LEFT(), and MID() are especially useful for extracting information from strings with set formats, such as ZIP Codes, locations, or ISBNs.

Resolving text problems is not magic but is accomplished with text functions.

Figure 8-10. Resolving text problems is not magic but is accomplished with text functions.

The num_chars argument must be greater than or equal to 0. If the value of num_chars is greater than the value of the text argument, the RIGHT() function returns the entire string. If the num_chars argument is not specified, the default value used is 1.

Example. In a spreadsheet column, the first name and last name are separated by a space. You want to extract the last name. Cell H4 contains the name. The following formula extracts the last name:

=RIGHT(H4,LEN(H4)-SEARCH(" ",H4))

You use the SEARCH() function to locate the space character. LEN() provides the total string length, and then the characters to the right of the space character can be extracted by using the RIGHT function.

See Also

LEFT(), LEFTB(), MID()