How to Extract the last N Words from Text String in Excel
Last Updated :
06 Dec, 2023
Excel is a tool for storing and managing a large amount of data. Data is entered in a rectangular block, which we called a cell. This tool can be used to perform different tasks like creating graphs and analyzing trends, to get insights from the data. It is primarily used for financial data analysis by accounting professionals. Let's learn how to extract the last N-word in Excel.
For example, we have a string "Welcome to GeeksforGeeks platform" and we need to extract the last 2 words from the string, then the output should be "GeeksforGeeks Platform".
How to Extract the Last N-Word in Excel
For demonstration, we will use the following string "Hello Geeks, Welcome to the GeeksforGeeks Platform". As an example, We will extract the last 5 words of the given string. Follow the below steps,
Step 1: Count the number of spaces in the string. The formula for counting spaces,
LEN(cell_name)-LEN(SUBSTITUTE(cell_name," ",""))
Example:

Output

Step 2: Replace the fifth space from the last with any special character like @. Formula is,
SUBSTITUTE(cell_name," ","@",(LEN(cell_name)-LEN(SUBSTITUTE(cell_name," ",""))-5+1)).
Example:

Output

Step 3: Get the location of the special character. Formula is,
LEN(cell_name)-FIND("@",SUBSTITUTE(cell_name," ","@",(LEN(cell_name)-LEN(SUBSTITUTE(cell_name," ",""))-5+1)))
Example:

Output

Step 4: Extract all the characters after the special characters. Formula is,
RIGHT(cell_name,LEN(cell_name)-FIND("@",SUBSTITUTE(cell_name," ","@",(LEN(cell_name)-LEN(SUBSTITUTE(cell_name," ",""))-5+1))))
Example:

Output

So, the final formula to get the last 5 words from the string is,
= RIGHT(cell_name,LEN(cell_name)-FIND("@",SUBSTITUTE(cell_name," ","@",(LEN(cell_name)-LEN(SUBSTITUTE(cell_name," ",""))-5+1))))
Replace 5 with the value of N to get the last N words from the string.
Formula to Extract Last-N words in Excel
= RIGHT(cell_name,LEN(cell_name)-FIND("@",SUBSTITUTE(cell_name," ","@",(LEN(cell_name)-LEN(SUBSTITUTE(cell_name," ",""))-N+1))))
In this article, I've shown you how to get the last n words out of a cell. Hopefully, this helps you out, I advise you to read more articles on Excel if you want to understand more. I appreciate your time and look forward to hearing from you soon!
Similar Reads
How to Extract the Last Word From a Cell in Excel Explore how to extract the last word from a cell in Excel. Whether youâre working with text data, names, or any other content, knowing this technique can be incredibly useful. In this article, we explain how to extract the last word from a text in a cell using the Excel function. Â Extracting words f
3 min read
How to Extract Text Only from Alphanumeric String in Excel? In the vast landscape of Excel spreadsheets, managing data efficiently is crucial for streamlined analysis and reporting. Often, one encounters the challenge of dealing with cells containing a mix of letters and numbers, commonly known as alphanumeric strings. Extracting only the text component from
4 min read
How to Extract Characters from a String in R Strings are one of R's most commonly used data types, and manipulating them is essential in many data analysis and cleaning tasks. Extracting specific characters or substrings from a string is a crucial operation. In this article, weâll explore different methods to extract characters from a string i
4 min read
How to Remove the Last Character From a Table in SQL? SQL (Structured Query Language) allows for efficient data manipulation and retrieval. A common task in SQL involves removing the last character from a specific column within a table. This can be achieved using string functions like SUBSTRING() and LEN(). In this article, we will demonstrate how to a
4 min read
How to get the last character of a string in PHP ? In this article, we will find the last character of a string in PHP. The last character can be found using the following methods.Using array() Method: In this method, we will find the length of the string, then print the value of (length-1). For example, if the string is "Akshit" Its length is 6, in
2 min read
How to Extract Text before @ Sign from an Email Address in Excel? You got a dataset and you want to extract the name part of the email address. This task can be done with a text to column and formula that uses the LEFT and FIND functions. Using LEFT and FIND functionsThe LEFT function: The LEFT function returns a given text from the left of our text string based o
3 min read