RIGHT() – Extracts rightmost characters from text
The RIGHT() function returns a specified number of characters from the end (right side) of a text string.
Syntax
RIGHT(text, numChars)
- text: The text string or a cell reference containing the text from which to extract characters.
- numChars: The number of characters to extract from the right of the text. This must be a non-negative integer.
Basic example
RIGHT(T1A1, 4)
Extracts the last 4 characters from the text in cell T1A1.
- If T1A1 = "Example Text": RIGHT(T1A1, 4) → "Text"
- If T1A1 = "MathGrid": RIGHT(T1A1, 4) → "Grid"
- If T1A1 = "Data" and you request more characters than available: RIGHT(T1A1, 10) → "Data" (returns the entire string)
- If T1A1 = "Information" and numChars is 0: RIGHT(T1A1, 0) → "" (an empty string)
Key features
- End-of-string extraction: Always extracts characters from the end of the input text.
- Handling of
numChars: If numChars is 0, it returns an empty string. If numChars is greater than the length of the text, it returns the entire text string. - Numeric conversion: If the text argument refers to a cell containing a number, that number will first be converted to text, and then RIGHT() will operate on that text representation.
Practical uses
- Extracting file extensions: RIGHT(filenameCell, 3) for a 3-letter extension.
- Getting the last few digits of an ID number.
- Isolating suffixes or trailing codes from a longer string.
- Checking the end of a string for specific characters or patterns.
Common mistakes
numCharsis negative: Providing a negative number for numChars will likely result in an error.numCharsis not a number: The numChars argument must be an integer or a cell reference pointing to one.- Text argument is a number but expecting string logic: e.g., RIGHT(12345, 2) will treat "12345" as text and return "45".
- Assuming left-to-right: RIGHT() always starts from the right. For left-to-right extraction, use the LEFT() function.
MathGrid ©
MathGrid ©