In the last few articles, we've discussed different Text functions - those that are used to manipulate text strings. Today our focus is on the RIGHT function, which is designed to return a specified number of characters from the rightmost side of a string. Like other Excel Text functions, RIGHT is very simple and straightforward, nevertheless it has a few unobvious uses that might prove helpful in your work.
Excel RIGHT function syntax
The RIGHT function in Excel returns the specified number of characters from the end of a text string.
The syntax of the RIGHT function is as follows:
Where:
- Text (required) - the text string from which you want to extract characters.
- Num_chars (optional) - the number of characters to extract, starting from the rightmost character.
- If num_chars is omitted, 1 last character of the string is returned (default).
- If num_chars is greater than the total number of characters in the string, all characters are returned.
- If num_chars is a negative number, a Right formula returns the #VALUE! error.
For example, to extract the last 3 characters from the string in cell A2, use this formula:
=RIGHT(A2, 3)
The result might look something similar to this:
Important note! The Excel RIGHT function always returns a text string, even if the original value is a number. To force a Right formula to output a number, use it in combination with the VALUE function as demonstrated in this example.
How to use RIGHT function in Excel - formula examples
In real-life worksheets, the Excel RIGHT function is rarely used on its own. In most cases, you will be using it together with other Excel functions as part of more complex formulas.
How to get a substring that comes after a certain character
In case you want to extract a substring that follows a specific character, use either SEARCH or FIND function to determine the position of that character, subtract the position from the total string length returned by the LEN function, and pull that many characters from the rightmost side of the original string.
Let's say, cell A2 contains the first and last name separated by a space, and you aim to pull the last name to another cell. Just take the generic formula above and you put A2 in place of string, and " " (space) in pace of character:
=RIGHT(A2,LEN(A2)-SEARCH(" ",A2))
The formula will yield the following result:
In a similar manner, you can get a substring that follows any other character, e.g. a comma, semicolon, hyphen, etc. For example, to extract a substring that comes after a hyphen, use this formula:
=RIGHT(A2,LEN(A2)-SEARCH("-",A2))
The result will look similar to this:
How to extract a substring after the last occurrence of the delimiter
When dealing with complex strings that contain several occurrences of the same delimiter, you may often need to retrieve the text to the right of the last delimiter occurrence. To make things easier to understand, have a look at the following source data and desired result:
As you can see in the screenshot above, Column A contains a list of errors. Your goal is to pull the error description that comes after the last colon in each string. An additional complication is that the original strings may contain different numbers of delimiter instances, e.g. A3 contains 3 colons while A5 just one.
The key to finding a solution is determine the position of the last delimiter in the source string (the last occurrence of a colon in this example). To do this, you will need to use a handful of different functions:
- Get the number of delimiters in the original string. It's an easy part:
- Firstly, you calculate the total length of the string using the LEN function: LEN(A2)
- Secondly, you compute the length of the string without delimiters by using the SUBSTITUTE function that replaces all occurrences of a colon with nothing: LEN(SUBSTITUTE(A2,":",""))
- Finally, you subtract the length of the original string without delimiters from the total string length: LEN(A2)-LEN(SUBSTITUTE(A2,":",""))
To make sure the formula works right, you can enter it in a separate cell, and the result will be 2, which is the number of colons in cell A2.
- Replace the last delimiter with some unique character. In order to extract the text that comes after the last delimiter in the string, we need to "mark" that final occurrence of the delimiter in some way. For this, let's replace the last occurrence of a colon with a character that does not appear anywhere in the original strings, for example with a pound sign (#).
If you are familiar with the syntax of the Excel SUBSTITUTE function, you may remember that it has the 4th optional argument (instance_num) that allows replacing only a specific occurrence of the specified character. And since we have already calculated the number of delimiters in the string, simply supply the above function in the fourth argument of another SUBSTITUTE function:
=SUBSTITUTE(A2,":","#",LEN(A2)-LEN(SUBSTITUTE(A2,":","")))
If you put this formula in a separate cell, it would return this string: ERROR:432#Connection timed out
- Get the position of the last delimiter in the string. Depending on what character you replaced the last delimiter with, use either case-insensitive SEARCH or case-sensitive FIND to determine the position of that character in the string. We replaced the last colon with the # sign, so we use the following formula to find out its position:
=SEARCH("#", SUBSTITUTE(A2,":","#",LEN(A2)-LEN(SUBSTITUTE(A2,":",""))))
In this example, the formula returns 10, which is the position of # in the replaced string.
- Return a substring to the right of the last delimiter. Now that you know the position of the last delimiter in a string, all you have to do is subtract that number from the total string length, and get the RIGHT function to return that many characters from the end of the original string:
=RIGHT(A2,LEN(A2)-SEARCH("$",SUBSTITUTE(A2,":","$",LEN(A2)-LEN(SUBSTITUTE(A2,":","")))))
As shown in the screenshot below, the formula works perfectly:
If you are working with a large dataset where different cells may contain different delimiters, you may want to enclose the above formula in the IFERROR function to prevent possible errors:
=IFERROR(RIGHT(A2,LEN(A2)-SEARCH("$",SUBSTITUTE(A2,":","$",LEN(A2)-LEN(SUBSTITUTE(A2,":",""))))), A2)
In case a certain string does not contain a single occurrence of the specified delimiter, the original string will be returned, like in row 6 in the screenshot below:
How to remove the first N characters from a string
Apart from extracting a substring from the end of a string, the Excel RIGHT function comes in handy in situations when you want to remove a certain number of characters from the beginning of the string.
In the dataset used in the previous example, you may want to remove the word "ERROR" that appears at the start of each string and leave only the error number and description. To have it done, subtract the number of characters to be removed from the total string length, and supply that number to the num_chars argument of the Excel RIGHT function:
In this example, we remove the first 6 characters (5 letters and a colon) from the text string in A2, so our formula goes as follows:
=RIGHT(A2, LEN(A2)-6)
Can the Excel RIGHT function return a number?
As mentioned in the beginning of this tutorial, the RIGHT function in Excel always returns a text string even if the original value is a number. But what if you work with a numeric dataset and want the output to be numeric too? An easy workaround is nesting a Right formula in the VALUE function, which is specially designed to convert a string representing a number to a number.
For example, to pull the last 5 characters (zip code) from the string in A2 and convert the extracted characters to a number, use this formula:
=VALUE(RIGHT(A2, 5))
The screenshot below shows the result - please notice the right-aligning numbers in column B, as opposed to left-aligned text strings in column A:
Why doesn't the RIGHT function work with dates?
Since the Excel RIGHT function is designed to work with text strings whereas dates are represented by numbers in the internal Excel system, a Right formula is unable to retrieve an individual part of a date such as a day, month or year. If you attempt to do this, all you will get is a few last digits of the number representing a date.
Supposing, you have the date 18-Jan-2017 in cell A1. If you try to extract the year with the formula RIGHT(A1,4), the result would be 2753, which is the last 4 digits of number 42753 that represents January 18, 2017 in the Excel system.
"So, how do I retrieve a certain part of a date?", you may ask me. By using one of the following functions:
- DAY function to extract a day: =DAY(A1)
- MONTH function to get a month: =MONTH(A1)
- YEAR function to pull a year: =YEAR(A1)
The following screenshot shows the results:
If your dates are represented by text strings, which is often the case when you export data from an external source, nothing prevents you from using the RIGHT function to pull the last few characters in the string that represent a certain part of the date:
Excel RIGHT function not working - reasons and solutions
If a Right formula does not work right in your worksheet, most likely it's because of one of the following reasons:
- There is one or more trailing spaces in the original data. To quickly remove extra spaces in cells, use either the Excel TRIM function or the Trim spaces tool.
- The num_chars argument is less than zero. Of course, you will hardly want to put a negative number in your formula on purpose, but if the num_chars argument is calculated by another Excel function or a combination of different functions and your Right formula returns the #VALUE! error, be sure to check the nested function(s) for errors.
- The original value is a date. If you have followed this tutorial closely, you already know why the RIGHT function cannot work with dates. If someone skipped the previous section, you can find full details in Why the Excel RIGHT function does not work with dates.
This is how you use the RIGHT function in Excel. To have a closer look at the formulas discussed in this tutorial, you are most welcome to download our sample workbook below. I thank you for reading and hope to see you on our blog next week.
Available downloads
Excel RIGHT function - examples (.xlsx file)
132 comments
I have this: T1234LA. But i want it to be T-1234LA.
How do I achieve that using right function so it can affect the other column(drop down)
Hi! To insert a character at a specific position in a text string, you can use the REPLACE function.
=REPLACE(A4,2,0,"-")
Hi If the text extracted from the cell is a number, can i use this in for a seperate equation?
Ex.
A1 = 45, 6
A2 = 53, 3
I can extract the numbers to the right or left of the comma into another cell. However when I try to eg. sum all the numbers on the right of the comma it returns as 0. Is it possible?
Thanks in advance!
Hello! When you extract a number to the right of a comma, it is returned as text. Convert this text to a number, such as this:
=--TEXTAFTER(A1,",")
For more information, please visit: How to convert text to number in Excel.
How can I test the last digit of a SUM(range) result see if it is zero eg SUM(A4:A8) = 1234.70.
The RIGHT function always returns '7'.
Hello! The last digit of your number is 7. You see 0 because the number format is set to two decimal places. The real number is 1234.7.
If you use the TEXT function to convert the number to text in the desired format, the last digit can be 0.
TEXT(SUM(A4:A8), "#.00") will return the text "1234.70"
I have a data like Shaym M Sunny, Suraj T S, them how can I extract the last name eg: Sunny and S from the names)
Hi! Here is the article that may be helpful to you: How to separate names in Excel: split first and last name into different columns.
Hi! I need your help.
I'm trying to use the RIGHT formula for this:
For instance:
A1: 24.0
I need "0" only to B1 cell.
Please help! thank you!
Please re-check the article above since it covers your task.
I want to remove last alphabets only character please suggest complete excel formula
LC21I142A
LC21L090L
LC21L093A
LC21L053C
Count the number of characters with the LEN function and extract all except the last character with the LEFT function. You can also delete the last character with the REPLACE function.
You can use these formulas:
=LEFT(A2,LEN(A2)-1)
=REPLACE(A2,LEN(A2),1,"")
Hello , i have some problem with this
i want to get this text as different coloumns
may can help me
Example : Name / Full name 123456789
how do i get the name , full name , and the number in different coloumns , thankyou .
Hi!
You can find the examples and detailed instructions here: Split string by delimiter or pattern, separate text and numbers. You can also use the new TEXTSPLIT function to split the text into cells.
Hi thanks for the clear explanation! I am trying to use the LEFT and RIGHT functions in conjunction with each other that concatenates the number of characters specified in Data Cell 02 from the left and right ends of the content in Data Cell 01.
data cell 1:
12abcd12
data cell 2:
2
Hi!
If I understand your task correctly, try the following formula:
=LEFT(A1,A2)&RIGHT(A1,A2)
For more information, please read: Combine text strings, cells and columns.
hi i please help me get the right formula:
ex.25,00
=RIGHT(A1;2)
i used the following formula: =RIGHT(A1,2) and the result was 25
?????
Thank you so much!
Hi!
If a number is written in A1, then this is 25. You use the "Number" format in the cell. You can convert number to text using the TEXT function in the format you need.
For example -
=TEXT(A2, "0.00")
Is there a way to use conditional If...then statements within a Right formula? For instance, I have a series of numbers that I would like to sort by the last number, not necessarily the last digit, because some numbers have a letter (or two) at the end, ie 1234A, 43353CC, 67890, etc. So they should be sorted in descending order according to 4, 3, and 0, but because the position of the last number changes, can't use a simple formula. How would I do this?
Hello!
To extract the last digit from text, you can use the RIGHT function and these guidelines: How to extract number from the end of text string.
=RIGHT(RIGHT(A2, LEN(A2) - MAX(IF(ISNUMBER(MID(A2, ROW(INDIRECT("1:"&LEN(A2))), 1) *1)=FALSE, ROW(INDIRECT("1:"&LEN(A2))), 0))),1)
I have a sentence mail.google.com, mail.yahoo.com... in column
I want to replace with mail_google.com, etc.
Hi!
To find and replace text in a cell, use the SUBSTITUTE function:
=SUBSTITUTE(A1,"mail.","mail_")
This should solve your task.
If I have common.annualRevenu.test, bdf.annualRevenu.test
to -- > common_annualRevenu.test, bdf_annualRevenu.test
then how it works?
Please.
Hello!
To replace characters in text, use SUBSTITUTE function.
=SUBSTITUTE(SUBSTITUTE(A1,".","_",3),".","_",1)
Hope this is what you need.
I could use some help please. How can I extract all characters to the right of the last pipe and space even when some strings have 1 or multiple pipes?
Example 1: Automotive/RV | Compasses - Magnetic,Marine Navigation & Instruments | Compasses,Marine Navigation & Instruments | Safety
Result 1: Safety
Example 2: Marine Navigation & Instruments | Safety
Result 2: Safety
I figured it out from the download example:
=RIGHT(E16,LEN(E16)-FIND("$",SUBSTITUTE(E16,"|","$",LEN(E16)-LEN(SUBSTITUTE(E16,"|",""))))-1)
Hello!
If I got you right, the formula below will help you with your task:
=RIGHT(A1,LEN(A1)-SEARCH("#",SUBSTITUTE(A1,"|","#",LEN(A1) - LEN(SUBSTITUTE(A1,"|",""))))-1)
Hi there!
thanks a bunch for your help.
I have this text on A1:
10.1.4.81'
I have this text on A2:
10.1.20.234
In need to figure out the position of the first "." starting from the RIGHT.
So I am expecting the results:
3
4
I cannot make it :(
Much appreciated,
Josu.
Hello!
Replace the last "." to "#" using the SUBSTITUTE function.
The formula below will do the trick for you:
=LEN(A1)-SEARCH("#",SUBSTITUTE(A1,".","#",LEN(A1) - LEN(SUBSTITUTE(A1,".",""))))+1
This should solve your task.
I need a formula that can convert text in the format 2/15/2022 2:16:09 PM to date and time dd-mmm-yyyy hh:mm [gives 15-Jan-2022 14:16] and should be able to work correctly even where the date provided is 12/31/2022 2:16:09 PM still in the same format [should give 31-Dec-2022 14:16]
Hello!
Try this formula:
=DATE(MID(A2,SEARCH("/",A2,SEARCH("/",A2)+1)+1,4), LEFT(A2, SEARCH("/",A2,1)-1), (MID(A2,SEARCH("/",A2)+1, SEARCH("/",A2,SEARCH("/",A2)+1)- SEARCH("/",A2)-1)))+ MID(A2,SEARCH(" ",A2)+1,20)
We have a ready-made solution for your task. I'd recommend you to have a look at our Text To Date Tool. It parses over 500 combinations representing dates in text format and converts them to regular Excel dates.
HI,
do you know of a good way to extract a word or phrase from a cell containing many words? i'm trying to extract "ticker" or "hero" or "hero 2" or "sidekick" using a formula so we know the location of the message. i tried doing a search function but i could only go two deep due to the errors.
=IFERROR(IF(SEARCH("sidekick",A1)>0,"sidekick","no"),IF(SEARCH("hero",A1)>0,"hero","no"))
header|click|ticker Take 10% off orders $129+ -- i'm trying to extract just "ticker"
homepage|click|hero C2002-ECOM @ $99 -- i'm trying to extract just "hero"
homepage|click|hero 2 Disaster Prep -- i'm trying to extract just "hero 2"
homepage|click|sidekick The BEST Deals This Month -- i'm trying to extract just "sidekick"
Hello!
Using the formula, you can extract the first word after the last separator "|" :
=LEFT(MID(SUBSTITUTE(A1,"|","#", LEN(A1)-LEN(SUBSTITUTE(A1,"|",""))), SEARCH("#",SUBSTITUTE(A1,"|","#",LEN(A1)-LEN(SUBSTITUTE(A1,"|",""))))+1,100), SEARCH(" ",MID(SUBSTITUTE(A1,"|","#",LEN(A1)-LEN(SUBSTITUTE(A1,"|",""))), SEARCH("#",SUBSTITUTE(A1,"|","#",LEN(A1)-LEN(SUBSTITUTE(A1,"|",""))))+1,100))-1)
I have a cell that includes the following (as an example) #14 Wisconsin at #3 Illinois.
I want to extract the state names into different cells. Is successfully isolated "Wisconsin" into a cell using your page on MID and SEARCH ("=MID(A3, SEARCH(" ",A3)+1, SEARCH(" ",A3, SEARCH(" ", A3)+1)-SEARCH(" ",A3)-1)" .
I am struggling to isolate "Illinois". I was trying to use the RIGHT LEN AND FIND functions in combination to no avail.
Any suggestion
Hi!
To extract the last word from the text, use the formula:
=RIGHT(SUBSTITUTE(A3," ","@",LEN(A3)-LEN(SUBSTITUTE(A3," ",""))), LEN(A3)-FIND("@",SUBSTITUTE(A3," ","@",LEN(A3) - LEN(SUBSTITUTE(A3," ",""))),1))
I hope my advice will help you solve your task.
I thought for a moment it worked, but I failed to anticipate something that complicates this.
In some cases what I am extracting is two words. For example #11 Texas at #42 Oklahoma St resulted in just "St" when I want " Oklahoma St" and for #7 Kansas at #19 W Virginia it resulted in just "W" when I need "W Virgnia"
This solution results in only the St being extracted from Oklahoma St - is there a way to tell excel that I need everything after the last space before the name.
Another suggestion is appreciated. It is so close.
Hi!
I wrote this formula based on the description you provided in your original comment. If you gave the correct description of the problem, time would not be wasted.
Try the following formula:
=MID(A1,SEARCH(" ",A1,SEARCH("#",A1,LEN(A1)-LEN(SUBSTITUTE(A1,"#",""))))+1,50)
Hi All,
I need to remove the first two digits from my excel cells if the length of the characters in greater than 10, i.e. I have cell phone numbers and the I want to remove the country code 91 from the cell phone numbers. I know the RIGHT Formula in excel =RIGHT(A1, LEN(A1)-2). But I need to use it with IF condition. I am trying this but it is not working. Can someone please help: =IF(LEN(A1>10) RIGHT (A1, LEN(A1)-2))
Hi!
Please check the formula below, it should work for you:
=IF(LEN(A1)>10,RIGHT(A1,LEN(A1)-2),A1)
Almost there for me, i just need help please, im trying to get the 6 characters that appear after the second to last backslash.
eg. in
\orange rule\apples are nice\pears rock\berrys are yum\strawberry
i need to get 'berrys' (its always 6 characters and always starts after the second to last backslash)
Hello!
Please use the following formula:
=MID(A2,SEARCH("#",SUBSTITUTE(A2,"\","#",LEN(A2)-LEN(SUBSTITUTE(A2,"\",""))-1))+1,6)
This should solve your task.
Hi Please help me with the below questions answer.
Input:
cast(trim(name) as string) as name
Null as address
Cast(id as decimal(38,10)) as id
Output:
Name
Address
Id
Hi!
To extract a string from the middle of the text, use the MID function.
Hi,
I have the following descriptions in my excel file.
"And[wondering looked a] me.
Her h[ir was thick ]ith many a curl
She w[s eight years old she s]id;
How ma[y may you b]?"
I need to extract the last word after the string "]". Can you please help with the formula?