The RIGHT function in Google Sheets is useful to return a substring from the end of a string.
Table of Contents
RIGHT function extracts a specific number of characters from the right side of a text value and returns that fraction.
Let’s take an example.
Sometimes you don’t need the whole content of a cell, but you just want to extract the last characters of cell content.
For example, when you work with URLs, you might want to cut off the “https://” from the beginning of them. 🔗
So how do we do that?
To do so, use the
RIGHT formula with just an input string and the length of the substring that you want to return from the right side of the text.
Let’s dive into the examples below, where we will deal with actual values and see how we can write our own RIGHT function in Google Sheets.
The Anatomy of the RIGHT Function
The syntax of the function defines how we should work with it. So the syntax (how we write) the
RIGHT function is as follows:
Let’s understand what the
RIGHT function and its attributes mean:
=the equal sign is how we start just about any function in Google Sheets.
RIGHTis our function. We will have to add the arguments
number_of_characters(optional) into it for it to work.
stringis the input text from which the function returns the right part.
number_of_charactersis an optional argument that specifies the number of characters to return from the right side of the text. The default value is 1, so if you don’t specify this number, the function returns the last single character of the text.
⚠️ A Few Notes to Make Your RIGHT Function Work Perfectly
- In case the
number_of_charactersis greater than or equal to the length of the original text, then the function returns the original source string.
number_of_charactersargument must be greater than or equal to 1.
- In addition, if you ignore the second argument, then only the one last character will be extracted.
RIGHTfunction has an opposite function which is the
LEFTfunction. Similarly, the
LEFTfunction returns a substring but from the left side of a text value instead of the right side. Read our previous article on How to Use LEFT Function in Google Sheets guide so you can clearly see the difference.
A Real Example of Using RIGHT Function
Let’s look at the example below to see how to use the RIGHT function in Google Sheets.
In the example above, we have a list of URLs, and originally they have “https://” at the beginning. This is column A with the full URLs.
For this guide, we will be removing these parts from the URLs and only keep the right side of them. We want to extract these useful URLs in column B.
As I have shown, the
RIGHT function needs two arguments: (1) the text you want to cut and (2) the number of characters you want to keep on the right side of the text.
However, we don’t have an exact number of characters we want to extract here. We only know how many characters we don’t need from the beginning of the URLs.
We need to calculate it with the use of other functions. That will be the
LEN function that counts the total number of characters of a string.
So we want to calculate the number of characters that we want to keep from the right side of the text values. To do this, we count the total number of characters and then subtract the number of characters we don’t need.
RIGHT formula we used in cell B2 is as follows:
Here’s what this function does:
- To start, we have actively selected the cell B2 where we want to write our formula. This is where we want to use the
RIGHTfunction to return the substring from the right side of the URL.
- We selected cell A2 that serves as our
stringargument containing the original text.
- Secondly, we calculated
number_of_charactersaccording to the length of the whole string and the length of “https://” that we want to cut off.
- To do this, we used the
LENfunction to get the total number of characters. We simply added one cell reference into it to count the characters in cell A2.
- We subtracted 8 because “https://” has precisely eight characters. This way, we ensure that the second argument of the
RIGHTfunction is the length of the whole text minus the length of “https://”.
RIGHTfunction returns the right side of the string without the first 8 characters.
- Finally, we applied the same function with the corresponding references to every URLs in the sheet.
Super easy, right?
You can try it by yourself by making a copy of the spreadsheet using the link I have attached below:
How to Use RIGHT Function in Google Sheets
Let’s begin writing our own RIGHT function in Google Sheets.
- To begin, click on the cell where you want to show your result to make it the active cell. For this guide, I will be selecting B2, where I wanted to extract the first useful URL.
- Next, type the equal sign ‘=’ to begin the function and then followed by the name of the function which is ‘
right‘ (or ‘
- Now you should see that the auto-suggest box will pop-up with the name of the functions that start with
RIGHT. Make sure to select the right one, because there are more of them!
- After the opening bracket ‘(‘, you add the variables. The first variable is the
stringyou want to cut. You can reference a cell or type your text directly between quotation marks. I’m using the cell reference A2 by simply clicking on it.
- Then, add a comma to separate the arguments. After that, you can write your formula that calculates
number_of_characters. It can be a number or a more complicated formula. For this example, use the
LENfunction to get the total number of characters. So start writing its name and select it from the auto-suggest box.
- Afterwards, click on the cell that has the original text to add it as the argument of the
LENfunction. For this guide, I will be clicking at cell A2 again. Type the ‘)‘ closing bracket.
- Then, you should think about how many characters do you want to cut off from the string. You start with the total number of characters, and you should subtract the number of unnecessary characters. In this example, “https://” has eight characters. With this in mind, I’m subtracting 8 from the length of the full URL.
- Press the Enter key to add the closing brackets ‘)‘ and to complete the function. As a result, you can see the substring without “https://” in cell B2.
- Drag down the function with your mouse to apply it to the whole list of URLs. You can do this by clicking on the little blue square in the bottom right corner of the cell.
That’s pretty much it to using the
RIGHT function in Google Sheets. Feel free to go through the other numerous Google Sheets formulas to create even more powerful formulas that can make your life much easier. 🙂