Example 1
Last four digits of a reference
C2 =RIGHT(A2,4)
Result: 0457
The result is the text "0457". The leading zero is kept because it is text, not a number.
C2 =RIGHT(A2,4) returns 0457
Returns the last characters of a piece of text, counting from the right.
Syntax
=RIGHT(, )
All versions of Excel.
Try it
Edit the formula in C2 or change the inputs. The sheet recalculates as you type.
C2 =RIGHT(A2,4) returns 0457
RIGHT returns the last characters of a piece of text. Use it to read the suffix of a code, the last four digits of an account number, or a file extension.
=RIGHT(A2) returns the final character.If num_chars is longer than the text, RIGHT returns the whole text. If it is 0, you get an empty string. A negative number returns #VALUE!.
Like LEFT, RIGHT always returns text, even when the characters are digits. =RIGHT("INV-2025-0457",4) returns the text "0457", including the leading zero. That is often what you want for an ID. If you need a number for a sum or a lookup, use =VALUE(RIGHT(A2,4)), which gives 457.
RIGHT reads the stored value. On a date cell showing 15-Mar-2025 the stored value is the serial 45731, so =RIGHT(B2,2) returns "31", which is not the day. Use DAY, MONTH, YEAR or TEXT for parts of a date.
A fixed count works when every item has a suffix of the same size, such as the last four digits of a card or account number. When the size varies, work it out from the position of a separator. To get a file extension from report.xlsx and budget.csv, find the dot with FIND and subtract it from the total length with LEN:
=RIGHT(A2,LEN(A2)-FIND(".",A2))
For budget.csv, LEN is 10 and the dot is at position 7, so RIGHT takes 3 characters: csv. This assumes there is only one dot. If a name can contain more than one, find the last one instead, or use TEXTAFTER with a negative instance number: =TEXTAFTER(A2,".",-1), available in Microsoft 365 and Excel 2024.
RIGHT is also how you hide most of an ID. ="****"&RIGHT(A2,4) shows only the last four characters. To remove the last characters instead of keeping them, use LEFT: =LEFT(A2,LEN(A2)-4).
A trailing space counts as a character. If a cell contains "0457 ", then =RIGHT(A2,4) returns "457 ". Data pasted from other systems often has hidden trailing spaces, so wrap the cell in TRIM when the result looks wrong: =RIGHT(TRIM(A2),4).
A2. A number is treated as the text it would show in a General-format cell.#VALUE!.Each example is a live sheet. Change the inputs or the formula and watch the result.
Example 1
C2 =RIGHT(A2,4)
Result: 0457
The result is the text "0457". The leading zero is kept because it is text, not a number.
C2 =RIGHT(A2,4) returns 0457
Example 2
C2 ="****"&RIGHT(A2,4)
Result: ****8877
RIGHT keeps the last four characters, and the ampersand puts the typed asterisks in front.
C2 ="****"&RIGHT(A2,4) returns ****8877
Example 3
C3 =RIGHT(A3,LEN(A3)-FIND(".",A3))
Result: csv
budget.csv has 10 characters and the dot is at position 7, so RIGHT takes the last 3. The same formula in C2 returns xlsx.
C3 =RIGHT(A3,LEN(A3)-FIND(".",A3)) returns csv
Example 4
C3 =TEXTAFTER(A3,"-",-1)
Result: B12
A negative instance number counts delimiters from the end, so this returns the text after the last dash. It needs Microsoft 365 or Excel 2024.
C3 =TEXTAFTER(A3,"-",-1) returns B12
Solve it in the sheet. Every answer is checked, with hints if you need them.
Task 1 of 2
In B2, return the last four characters of the file name in A2.
Answer in B2.
=RIGHT("INV-0457",4) is the text "0457", which won't match the number 457 in a lookup. Use VALUE(RIGHT(...)) if you need a number.=RIGHT(B2,2) returns "31" from the serial number 45731. Use DAY, MONTH, YEAR or TEXT.num_chars fails when suffix lengths vary. Use LEN and FIND to work out the length, or TEXTAFTER in Microsoft 365.=RIGHT(A2,4) on "0457 " returns "457 ". Wrap the cell in TRIM when data comes from another system.#VALUE! when the separator is missing, and that error passes through RIGHT. Wrap the formula in IFERROR if some cells may have no separator.Use `=RIGHT(A2,4)`. The second argument is the number of characters to keep from the end.
Use `=RIGHT(A2,LEN(A2)-1)`. LEN counts all characters, and RIGHT keeps all but the first. `=MID(A2,2,LEN(A2))` also works.
In Microsoft 365 or Excel 2024, use `=TEXTAFTER(A2," ",-1)`. In older versions, a common trick for the last word is `=TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100))`, which works while the last word is under 100 characters.
RIGHT keeps them: it returns text, and text keeps its zeros. They disappear only when you convert the result with VALUE, because a number has no leading zeros.
RIGHT returns the whole text without padding it. `=RIGHT("A7",10)` returns "A7".
RIGHT is taught in Logic and text, lesson 10: LEFT, RIGHT and LEN. Each lesson is a short, graded exercise like the one above.