How to use Excel RIGHT function - formula examples

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:

RIGHT(text, [num_chars])

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: Using the RIGHT function in Excel

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.

RIGHT(string, LEN(string) - SEARCH(character, 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: Right formula to extract a substring after a space

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: Right formula to extract a substring after a hyphen

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: Source data and expected 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:

  1. 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.

  2. 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

  3. 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.

  4. 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: Extracting a substring after the last occurrence of the delimiter

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: An improved formula to extract a substring after the last occurrence of the delimiter

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:

RIGHT(string, LEN(string)-number_of_chars_to_remove)

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) Using the Excel RIGHT function to remove the first 6 characters from a string

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: Use the RIGHT function in combination with VALUE to return a number.

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. The Excel RIGHT function cannot be used on dates.

"So, how do I retrieve a certain part of a date?", you may ask me. By using one of the following functions:

The following screenshot shows the results: Use the Day, MONTH or YEAR function to get individual parts of a date.

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: If a date is represented by a text string, a Right formula works correctly.

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:

  1. 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.
  2. 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.
  3. 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

  1. By the way, I used CONCATENATE(A1,",",A2,"," so on and so forth. However, if cells are empty it displays a comma.

    Something like this
    125306920, 125298912,125297627,,,,,,,,,,

  2. Hi Everyone,

    Good day to all! I don't know what to use or how to use the code. But what I need is put a comma after every 9th number.

    Column A
    125306920
    125298912
    125297627
    125300893
    125311521
    125306307

    And if i use CONCATENATE i get this result 125306920125298912125297627125300893125311521125306307. Please help.

    Thanks a lot!

      • Good day! TEXTJOIN doesn't seem to work in 2013, if it's a plugin/addin i'm not allowed to download it either. :(

  3. Hello guys,

    Can you help me with this. I want to achieve the column B result given the column A as my data.

    In column A: ThePLAN 599 With iPhone 12 128GB Red
    ThePLAN 2799 with iPhone 12 Pro Max 256GB Gold
    ThePLAN PLUS 2999 (Consumable 1299)
    ThePLAN PLUS 599 (Consumable 299)

    Column B shows:

    iPhone 12 128GB Red
    iPhone 12 Pro Max 256GB Gold
    TPP
    TPP

    Thank you,

    • Hello!
      If I understand your task correctly, the following formula should work for you:

      =IFERROR(RIGHT(A1,LEN(A1)-SEARCH("with",A1,1)-4),"TPP")

      I hope it’ll be helpful.

      • Woah! it really worked! Thanks a lot!!!!

  4. HOW CAN WE GET NUMBER AFTER THE LAST COMMA IN EXCEL

    question - 1, 2, 5, 25, 223

    answer should be 223

    question - 1,2,5,25, 42

    answer should be 42

    • Hello!
      The formula below will do the trick for you:

      =RIGHT(SUBSTITUTE(C1,",","#", LEN(C1)-LEN(SUBSTITUTE(C1,",",""))), LEN(C1)-FIND("#",SUBSTITUTE(C1,",","#", LEN(C1)-LEN(SUBSTITUTE(C1,",",""))),1))

      Hope this is what you need.

  5. Hi. what function (and how) do I have to use with this given data?
    ECON:F6797-1111
    ECON:M9350-1
    CS:F5738-1111
    AC:M4799-1111
    HRDM:M7415-111
    AC:M7056-1111

    1 = 2016-2017
    11 = 2017-2018
    111 = 2018-2019
    1111 = 2019-2020

    only the last character. I know how to extract the (1,11,111,111 with this function =RIGHT(A2,LEN(A2)-SEARCH("-",A2))) but I do not know how to replace those values according to its year equivalent.

  6. I need to substitute the rightmost character so that my column will sort properly:
    if rightmost ="a", make it ".1"
    if rightmost ="b", make it ".2"
    I've tried everything but I don't get the result I need. Please help.

    • Hello
      Here is the formula that should work perfectly for you:

      =IF(RIGHT(C1,1)="a",REPLACE(C1,LEN(C1),1,".1"), IF(RIGHT(C1,1)="b",REPLACE(C1,LEN(C1),1,".2")))

      Hope this is what you need.

  7. Team, I hope this message finds you and your families all doing well. Need help and can't seem to get Excel to do what I want. I have an excel spreadsheet with IP addresses e.g. 10.9.1.100 I want to subtract the last Octet by 1 and have the output return the revised IP address.
    Example: Column A2 10.9.1.100
    Column A3 (suggested Formula)
    Column A4 output from A3 10.9.1.99
    Thank you for any help you can provide

    • Hello!
      If I understand your task correctly, the following formula should work for you:

      =LEFT(A2,SEARCH("#",SUBSTITUTE(A2,".","#",3),1)) & (--MID(A2,SEARCH("#",SUBSTITUTE(A2,".","#",3),1)+1, LEN(A2)-SEARCH("#",SUBSTITUTE(A2,".","#",3),1))-1)

      I hope this will help

  8. Hi Team,

    How can i extract the file name alone in the below mentioned link, like "Input form.xlsb" cause the file name will dynamic one.can you help me
    C:\Users\UST901\Desktop\Confidential\New Report\Input form.xlsb
    Thanks\Raju

  9. Hello!
    I have a text in a cell. Sometimes this text has at the end one empty space (it is visible only if I enter in the cell and go with the cursor to the most right of the text in the cell). I would like to use the right function (or any other function if feasible) in order to take this empty space out of the text in the cell (however the tricky part is that the formula should work only if there is a space in the end of the text, if it is a symbol it should not change the text. Also the formula should not delete other empty spaces within the text, only the empty space at the end of the text). Thanks!

    • Hello Ivan!
      If I understand your task correctly, the following formula should work for you:

      =IF(RIGHT(D1,1)=" ",REPLACE(D1,LEN(D1),1,""),D1)

      I hope this will help

  10. Hi, I too needed the below case? out put last 4 digit from the different lenth of datas as below.
    Original: To be
    ABCDEF-12345 ABCD-2345
    ABCD-23456 ABCD-3456
    ABC-34567 ABC-4567
    AB-45678 AB-5678
    Thanks in advance.

    • Hello!
      I hope you have studied the recommendations in the above tutorial. To display the last 4 digits as number, use the RIGHT function, as described in the article above
      =--RIGHT(A1,4)

  11. I want to exclude the last 2 caracters

  12. Please see the following string:
    Cell A1 = Arch Psychological Services 39-9912 106 Street, Edmonton, Alberta T5K 1C5
    I am trying to separate the name of the business and the address as follows:
    Cell B1 = Arch Psychological Services
    Cell C1 = 39-9912 106 Street, Edmonton, Alberta T5K 1C5
    How would you use the RIGHT function? or any other function?
    Thanks

    • Hello ,
      I want the output this type 101, 1000, 102.
      Please Give me a solution.

      1. ZSW234ER101
      2. ZSW234ER1000
      3. ZSW234ER102

  13. Help Please, this is eating my brain.
    I have a Title String example
    ex: Title = Waterfront (0000000) created 11/18/2019 8:47 AM | Kitchen | Morgan Stanley | Georgia | Ashok Masetty

    I need value "Georgia" and "Ashok Masetty" seperately but I am getting "Georgia | Ashok Masetty" using the below formula
    =RIGHT(RIGHT(RIGHT(Title,LEN(Title)-INT(FIND("|",Title))),LEN(RIGHT(Title,LEN(Title)-INT(FIND("|",Title))))-INT(FIND("|",RIGHT(Title,LEN(Title)-INT(FIND("|",Title)))))),LEN(RIGHT(RIGHT(Title,LEN(Title)-INT(FIND("|",Title))),LEN(RIGHT(Title,LEN(Title)-INT(FIND("|",Title))))-INT(FIND("|",RIGHT(Title,LEN(Title)-INT(FIND("|",Title)))))))-INT(FIND("|",RIGHT(RIGHT(Title,LEN(Title)-INT(FIND("|",Title))),LEN(RIGHT(Title,LEN(Title)-INT(FIND("|",Title))))-INT(FIND("|",RIGHT(Title,LEN(Title)-INT(FIND("|",Title)))))))))

    Any help is appreciated.

    Thanks

  14. I have set of alphanumeric employee ID, like 00PTPL-001 next will be 00PTLP-00101, length of alphanumeric ID is not same of all. From this ID I need to extract ID by removing first two zeroes and last two digits if added with employee ID. Unable to use MID function, because both sides of colon text has to be extracted. Kindly help with one dynamic formula to remove leading and trailing unwanted digits and texts.

  15. Hi,
    this formula did not work for me. the formula brought the same text back. no change. any idea why?
    Lidia

  16. Hi,
    I'm using Right and Left functions to get the first and last names on a cell, they are separated by comma. The solution doesn't bring up the total number of values before and after the comma i.e. for the full name "Soberado,Veronica"
    The Left function (without -1 at the end) comes as "Soberad" and if I place the "-1" to get the position just before the comma, then it comes as "Sobera".
    The Right function comes as "eronica" (missing the V).
    This is all part of a bigger equation where I am doing a lookup to find the Full Name in the array and then I separate the name in First and Surname, so not sure if these equations are able to work together or not. See below:
    =RIGHT(INDEX(Mob_Database,MATCH($F$15,Mob_Database[Staff_No],0),6),SEARCH(",",Mob_Database[Title]))
    I'm a beginner using Excel, so would really appreciate some advice and provide some potential explanation of why this is not working.
    Many thanks in advance.
    Clara

  17. Hi, if anyone could help with the below case?
    Original: To be
    ABCDEF-12345 ABCD-2345
    ABCD-23456 ABCD-3456
    ABC-34567 ABC-4567
    AB-45678 AB-5678
    Thanks in advance.
    David

  18. Hi, anyone could help with the below example ?
    Example:
    psky90000-11+L1234567.1+Q10000+000000
    pshd2b831mm111a+L1234567.11+Q10000+0000”0
    How I use the right function formula can get with the L no I need in one column I can fill in 2 type of different data.

  19. Hi if someone could help,
    If I have several domains but I get duplicate but different tld (.com, .net, .org, .fr, etc)
    what formula can I use to get the tld only ?

    • Hi Loris,

      Is my understanding correct that you want to get only .com, .net, .org, .fr, etc. ? If so, you can use the following formula to extract everything that comes after a dot, including a dot itself:

      =IFERROR(RIGHT(A2,LEN(A2)-SEARCH(".",A2)+1), "")

      Where A2 is the cell containing the original domain.

  20. I'm using the right and left formula, to separate a number with a coma into to numbers, example:

    CELL D18 = 10.50
    left cell formula - =LEFT(D18,2) = 10,
    the right cell formula =RIGHT(D18,2) = .5

    How can I tell the formula to count "0" as part of the number? Taking into account that not all the number's in cell D18 have "0"'s (ex: my D18 cell can be 10.85, in this case the right formula works perfectly).

    Thank you,
    Carolina

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)