Skip to main content

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.


Extract first word or last name from text string with Formulas

If you need to extract the first word from a list of text strings, the following formulas can help you.

To extract the first word, please enter below formula into a blank cell, and then drag this cell's AutoFill handle to the range as you need.

=IF(ISERR(FIND(" ",A2)),"",LEFT(A2,FIND(" ",A2)-1))

To extract the last word from each cell, please apply this formula:

=IF(ISERR(FIND(" ",A2)),"",RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2," ","*",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))))))

And now you will see the first or the last word is extracted from each cell.

Notes: In above formulas, A2 indicates the cell you will extract the first or the last word from.

Hard to memorize long complicated formulas? Amazing tool help you extract the nth Word with several clicks only!

Above long formulas can only extract the first and the last word, but will be useless to extract the specified nth word, says the second word, the sixth word, etc. Even you can figure out formulas to solve the problem, the formulas must be too complex to memorized and applied. Here, the Extract the nth word in cell feature of Kutools for Excel is recommended, and it will help you extract the nth word as easy as possible!


Kutools for Excel - Includes more than 300 handy tools for Excel. Full feature free trial 30-day, no credit card required! Get It Now

Extract nth word from text string with User Defined Function

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.


Extract each word from text string and list them horizontally or vertically

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 - Includes more than 300 handy tools for Excel. Full feature free trial 30-day, no credit card required! Free Trial Now!

1. Select the text string cells that you will extract their words from, and click the Kutools > Merge & Split > 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:

3. Now specify the destination range that you will output extracted words into, and click the OK button

If you checked the Split to Columns option in the above Split Cells dialog, every word is extracted from every text string and listed vertically.

If you checked the Split to Rows option in the above Split Cells dialog, every word is extracted from every text string and listed horizontally.


Extract the nth word from text string in Excel with an amazing tool

If you have installed Kutools for Excel, you can use its Formula Helper > Extract the nth word in cell feature to quickly extract the nth word from the specified cell easily.

Kutools for Excel - Includes more than 300 handy tools for Excel. Full feature free trial 30-day, no credit card required! Free Trial Now!

1. Select the cell you will put the extracted word at, and click Kutools > Formula Helper > Formula Helper to enable this feature.

2. In the Formulas Helper dialog, please do as follows:
(1) Select Text from the Formula type drop-down list;
(2) Click to highlight Extract the nth word in cell in the Choose a formula list box;
(3) In the Cell box, specify the cell that you will extract word from;
(4) In The Nth box, specify the number.

3. Click the Ok button. If necessary, please drag the AutoFill Handle of the formula cell and copy the formula to other cells.


Demo: extract each word from text string and list them horizontally or vertically


Kutools for Excel includes more than 300 handy tools for Excel, free to try without limitation in 30 days. Download and Free Trial Now!

Related articles:

Best Office Productivity Tools

Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolset12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   Many More...

Kutools for Excel boasts over 300 features, ensuring that what you need is just a click away...

Supports Office/Excel 2007-2021 & newer, including 365   |   Available in 44 languages   |   Enjoy a full-featured 30-day free trial.

kte tab 201905


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (38)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I've created the FindWord custom function as described and it worked perfectly but it stopped working the next day. I looked in the VBA window and the Module is still there. Any idea why the function is not working anymore?
This comment was minimized by the moderator on the site
Dark Chocolate 25gm box 12 pcs

Dark Chocolate 20gm*24 box

White Chocolate 15gm

White Chocolate 25gm*24

Biscuits W/Marshmallow300gm

Chocolate 40gm

Can some plz help to extract the numbers before "gm", for example : 25,20,15,25,300,40
This comment was minimized by the moderator on the site
Hi I would like to know how to use the VBA model but I have sentences of only one word, and i would like to pick the first word even if there is only one word.

Thank you
This comment was minimized by the moderator on the site
Hi Maura,
The VBA cannot extract the first word if there is only word in the cell. However, it’s recommended to apply the Text to Column to extract the first word of every cell in a column quickly.
1. Select the column, copy, and paste in a blank column.
2. Keep the new column selected, click Data > Text to Column.
3. In the Text column dialog, select Delimited, and then check Space as delimiters, and finally click Finish.
4. Now all words are separated by space. For the extracted words, you can remove all columns except the first one.
This comment was minimized by the moderator on the site
i want to remove the last word in cell and data is like this "/Document/CstmrCdtTrfInitn/PmtInf/CdtTrfTxInf/Cdtr/CtctDtls/FaxNb" can i have formula
This comment was minimized by the moderator on the site
Thanks 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.)
This comment was minimized by the moderator on the site
Thank you! It works fine called in a Sub.
This comment was minimized by the moderator on the site
the 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
This comment was minimized by the moderator on the site
The 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
This comment was minimized by the moderator on the site
Hi, I am having cell with values like SAN_UN_TC1,SAN_UN_TC2,PEP_HR_TC1 I would like to extract first words liek SAN /PEP into one cell and words liek UN/HR to another cell How could i do it, Any help is appreciated. Thanks, Shiva
This comment was minimized by the moderator on the site
If number of characters in string (SAN_UN_TC1) is fixed (3_2_3), it's simple: column 1: =LEFT(B15,3) column 2: =MID(B15,5,2) column 3: =RIGHT(B15,3)
This comment was minimized by the moderator on the site
Many thanks for sharing VBA code....saved me a lot of time
This comment was minimized by the moderator on the site
VBA is so useful - thanks for sharing!
This comment was minimized by the moderator on the site
I would like to extract the first word on A1 and put it in front of a word in B1. what's the formula to do that? Thanks!
This comment was minimized by the moderator on the site
I'm looking for a formula that will pull out the First and Last Name in a text string. I've tried the formula here, which is amazing by the way, and it works great until it comes across a surname that is not hyphenated. Here is a sample of the text strings I'm presented with: example 1: Mouse, Mickey Justin M Feb 10 example 2: Hall Mouse, Minnie Jean F Mar 18 For string example 1, the formula/function here works great. For example 2 I get "Hall, Mouse". Here is the Excel formula I'm running: =CONCATENATE(LEFT(A2,FIND(", ",A2)+1), 'Personal Macro Workbook'!FindWord(A2,2)) Is there a way to modify the user defined function so that it looks for the first word to the right of the ","?
This comment was minimized by the moderator on the site
Remove the last name from the string you feed to the FindWord function: - find the comma position - subtract this from the total length of the string - use the remaining 'RIGHT' side of the original string =CONCATENATE(LEFT(A2,FIND(", ",A2)+1),FindWord(RIGHT(A2,LEN(A2)-FIND(", ",A2)-1),1))
This comment was minimized by the moderator on the site
First word. Copy/paste the column, select the contents of the new column, replace " *" with "". Last word. Copy/paste the column, select the contents of the new column, replace "* " with ""
This comment was minimized by the moderator on the site
ITS WORKING that's good. really helpful for us.
This comment was minimized by the moderator on the site
I have 64bit Excel 2013 and am missing the Morefunc addin. Based on the code above, I have come up with this replacement for Morefunc's WMID function. I would be grateful if anyone more expert than me could perform any tidying of it. Function WMid1(Source As String, Optional Position As Integer, Optional WordCount As Integer, Optional Separator As String) Dim arr() As String Dim xCount As Integer Dim wCount As Integer Dim wFirst As Integer Dim wLast As Integer If Position = 0 Then Position = 1 If WordCount = 0 Then WordCount = 1 If Separator = "" Then Separator = " " arr = VBA.Split(Trim(Source), Separator) xCount = UBound(arr) + 1 If Position < 1 Then wFirst = Application.Max(xCount + Position - WordCount + 1, 0) wLast = xCount + Position Else wFirst = Position - 1 wLast = Application.Min(xCount - 1, Position + WordCount - 2) End If If xCount < 2 Or Abs(Position) > xCount Then WMid1 = "" Else WMid1 = arr(wFirst) For wCount = wFirst + 1 To wLast WMid1 = WMid1 & Separator & arr(wCount) Next End If WMid1 = Trim(WMid1) End Function
This comment was minimized by the moderator on the site
Hi geeks, I have a cell like this: 1 ABCD; 2 DEDF; 1 DED#3d; 4 FDWDS; 1 ED And I would like to extract character after 1. So desired to have a result as below: ABCD;DED#3d;ED
This comment was minimized by the moderator on the site
Try this (see my reply above): Function FindWord(Source As String, Position As Integer) ' gets 1st, 2nd, last(0), second to last(-2) etc, word from a string ' Update 20150505 Dim arr() As String arr = VBA.Split(WorksheetFunction.Trim(Source), " ") xCount = UBound(arr) Select Case Position Case -xCount To 0 FindWord = arr(Position + xCount) Case 1 To xCount + 1 FindWord = arr(Position - 1) Case Else FindWord = "" End Select
This comment was minimized by the moderator on the site
I can't get the code for the first word to work if some of my list has only one word in the cell. e.g. first word ---> first second ---> [null] last word ---> last
This comment was minimized by the moderator on the site
Hi.. Thanks for your code, i have list sentences, and one of them just 1 word, and your code not work if its just only have 1 word..
This comment was minimized by the moderator on the site
Thank You soooo MUCH!!
This comment was minimized by the moderator on the site
Thanks, Alan, this is great, thanks! :)
This comment was minimized by the moderator on the site
Hi, just an addition to the code yesterday. This adds an extra line to adjust for redundant spaces in the source string: arr = VBA.Split(WorksheetFunction.Trim(Source), " ") regards, Allart
This comment was minimized by the moderator on the site
Hi, Thanks for your piece of code. It inspired me to expand a little. With the next lines, you can select: last word (0), one but last (-1), second to last (-2) etc. Regardless of number of words. Function FindWord(Source As String, Position As Integer) 'Update 20150504 Dim arr() As String arr = VBA.Split(Source, " ") xCount = UBound(arr) Select Case Position Case -xCount To 0 FindWord = arr(xCount + Position) Case 1 To (xCount + 1) FindWord = arr(Position - 1) Case Else FindWord = "" End Select End Function
This comment was minimized by the moderator on the site
Much appreciated. It helped me a lot.
This comment was minimized by the moderator on the site
how can we change fonts for nth word in a cell
This comment was minimized by the moderator on the site
This does not work properly on a source string made up of non-words (like vendor names followed by part numbers)
This comment was minimized by the moderator on the site
Hi, This really saves a lot of time. Thanks for sharing Can someone also suggest how we can extract the words with vba in a reverse way, e.g last word is 1, the second from right to left is 2 and so on. This will be much appreciated.
This comment was minimized by the moderator on the site
Good one. This worked very well
This comment was minimized by the moderator on the site
Hi, This is excellent. It worked very well and reduces our strain saves lots of time in this operation. Thanks to all who worked on this and shared...
This comment was minimized by the moderator on the site
Hi, I was just wondering what else I could insert into the Visual Basic formula that could extract and commas or dashs immediatly after the data.. for e.g. Fortin-
This comment was minimized by the moderator on the site
This was SUPER helpful, I was wondering if anyone knew of a downloadable, or a copy and pastable list of helpful hand made functions such as the "FindWord" that I would be able to use.
This comment was minimized by the moderator on the site
Thanks a lot! Worked fine! :-)
This comment was minimized by the moderator on the site
This user-defined function is awesome! Thanks a ton for sharing it.
This comment was minimized by the moderator on the site
That vba code is fantastic, thanks a lot.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations