The RIGHT function in Excel
RIGHT returns a set number of characters from the end of a text value. It's ideal when the part you need sits at the end, like the last four digits of an account or a size code on a SKU. Combine it with LEN and FIND when the length varies, such as a file extension.
Syntax
=RIGHT(text, [num_chars])
| text | The text or cell to take characters from. |
|---|---|
| num_chars | Optional. How many characters to return, counting from the right. If left out, you get just the last character. |
Try it yourself
This is a live spreadsheet. Type the formula and press Enter.
The last 2 characters of each SKU are the size code. In C2, use RIGHT to extract the size from the SKU in A2.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Size | ||||||
| 2 | Crew tee | ||||||
| 3 | Zip hoodie | ||||||
| 4 | Field jacket | ||||||
| 5 | Crew tee | ||||||
| 6 | |||||||
| 7 | |||||||
| 8 |
Tip: Tell RIGHT which cell to read and how many characters the size code has.
Examples
=RIGHT(A2,4)→ "8823"Returns the last four characters of the account number.
="****"&RIGHT(A3,4)→ "****7104"Masks an account number so only the last four digits show, a common requirement for reports shared outside the finance team.
=RIGHT(B3,LEN(B3)-FIND(".",B3))→ "xlsx"The full length minus the position of the dot is the number of characters after it. That gives the file extension, whatever its length.
Example data
| 1 | Account | File name | Full name |
|---|---|---|---|
| 2 | ACC-00418823 | INV-3391.pdf | Grace Hopper |
| 3 | ACC-00977104 | Q3 forecast.xlsx | Alan Turing |
Common mistakes
Trailing spaces
A cell that ends with a space returns that space as part of the result. Clean it first:
RIGHT(TRIM(A2),4).The result is text, not a number
RIGHT(A2,4)returns "8823" as text, so it won't match a number in a lookup. Wrap it in VALUE when you need a real number.Hardcoding a length for variable text
RIGHT(B2,3)works for "pdf" but returns "lsx" for "xlsx". Calculate the length with LEN and FIND.Names with more than two words
RIGHT(A2,LEN(A2)-FIND(" ",A2))finds the first space, so "Mary Jane Watson" returns "Jane Watson". In Microsoft 365,TEXTAFTER(A2," ",-1)takes the text after the last space.
FAQ
How do I get the last word in a cell?+
In Microsoft 365, use =TEXTAFTER(A2," ",-1). For a two-word name in any version, =RIGHT(A2,LEN(A2)-FIND(" ",A2)) works.
How do I remove the first few characters?+
Keep everything except them: =RIGHT(A2,LEN(A2)-4) drops the first four characters.
What if num_chars is bigger than the text?+
RIGHT returns the whole text, without an error.
Lesson
Master RIGHT step by step: LEFT, RIGHT, MID and LEN
Split product codes and IDs into their parts by taking characters from the start, end or middle of the text.