How to extract first / last / nth word from text string in Excel?
Have you ever suffered with the problem that you need to extract a certain word from the text string in a worksheet? For example, you have the following range of text strings needed to get the first/last or nth word from them, here I can talk about some effective ways for you to solve it.
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
Looking to extract the first word from a list of text strings, the following formulas can help you.
To extract the first word, please enter this formula =IF(ISERR(FIND(" ",A2)),"",LEFT(A2,FIND(" ",A2)-1)) into a blank cell, and then drag this cell's AutoFill handle to the range as you need.
And now you will see the first word is extracted from each cell. See screenshot below:
(1) In above formula, A2 indicates the cell you want to apply this formula.
(2) For extracting the last words from each cell, please apply this formula: =IF(ISERR(FIND(" ",A2)),"",RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2," ","*",LEN(A2)-LEN(SUBSTITUTE(A2," ","")))))).
|Formula is too complicated to remember? Save the formula as an Auto Text entry for reusing with only one click in future!
Read more… Free trial
If you want to extract the second, third or any nth word from the text string, you can create a user defined function to deal with it.
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module window.
Function FindWord(Source As String, Position As Integer) 'Update 20131202 Dim arr() As String arr = VBA.Split(Source, " ") xCount = UBound(arr) If xCount < 1 Or (Position - 1) > xCount Or Position < 0 Then FindWord = "" Else FindWord = arr(Position - 1) End If End Function
3. Then save the code, in this example, I will get the third word from the string, so type this formula =findword(A2,3) into a blank cell B2, and then drag this cell's AutoFill handle to the range as you need. See screenshot:
Note: In the above formula, A2 is the cell where you want to extract word from, the number 3 indicates the third word in the string that you will extract, and you can change them as you need.
This method will introduce Kutools for Excel's Split Cells utility to extract each word from text string cells, and then list extracted words horizontally or vertically based on your need.
Kutools for Excel - Combines more than 300 Advanced Functions and Tools for Microsoft Excel
1. Select the text string cells that you will extract their words, and click the Kutools > Text > Split Cells.
2. In the opening Split Cells dialog box, specify the split type in the Type section, check the Space option in the Specify a separator section, and click the Ok button. See screenshot:
Note: To list all extracted words of each text string cell horizontally, please check the Split to Columns option; to list all extracted words of each text string cells vertically, please check the Split to Rows option. In our case, we check the Split to Rows option.
3. In opening new dialog box, select a single cell of range that you will output extracted words into, and click the OK button. See screenshot above:
Then you will see all words are extracted from each text string cell and listing vertically as below screenshot shown:
Checking Split to columns option will horizontally list all extracted words from each text string as below screenshot shown:
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 1 years agoi want to remove the last word in cell and data is like this "/Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf/Cdtr/CtctDtls/FaxNb" can i have formula
To post as a guest, your comment is unpublished.· 1 years agoThanks so much for these! I have a question, though: how do I extract a number or group of numbers from a cell or textbox? For instance, if I have [37.5" x 21'] in cell A1, how could extract 37.5 into A2? There could be any number of characters and numbers in A1, but I'll always want the first number to the left of the "X", and the first number to the right. Not sure if you've covered something like this elsewhere, so I thought I'd ask here.
(Not sure if this went through the first time, so here it is again.)
To post as a guest, your comment is unpublished.· 2 years agoThank you! It works fine called in a Sub.
To post as a guest, your comment is unpublished.· 2 years agothe original formula isn't working for me, I keep getting #NAME?, anyone able to help? I am using Excel 2013 and this VBA would save me sooooo much time
To post as a guest, your comment is unpublished.· 2 years agoThe original VBA code posted here would save me so much time, however whenever I type in the =findword formula, I then get #NAME?, anyone able to help me? I am using Excel 2013
- ← Previous
- Next →