Excel guide · 4 min read
How to extract the first, last or nth word in Excel
=TEXTBEFORE(A2," ") and for the last word =TEXTAFTER(A2," ",-1) in Excel 365 or 2024. In any version, =LEFT(A2,FIND(" ",A2&" ")-1) returns the first word and =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)) the last. Wrap the cell in TRIM first if it may have extra spaces.Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | |
|---|---|---|
| 1 | Item description | Units |
| 2 | Cotton Hoodie Navy XL | 38 |
| 3 | Socks | 120 |
| 4 | Wool Beanie Grey OS | 54 |
| 5 | Rain Jacket Olive L | 17 |
| 6 | Silk Scarf Ivory | 22 |
Download this sheet as an Excel practice file (.xlsx)
The first word: TEXTBEFORE (Excel 365 / 2024)
The sheet is a shop export where each description starts with the material and ends with the size. TEXTBEFORE returns everything before the first space, so =TEXTBEFORE(A2," ") gives Cotton.
Two cells will trip it up. A3 is just Socks, with no space at all, and TEXTBEFORE returns #N/A when it cannot find the delimiter. A5 starts with a space, so the text before that first space is nothing, and the result is an empty cell. The formula below handles both: TRIM removes the leading space, and the sixth argument, if_not_found, returns the whole cell when there is no space.
Result: Rain
Rain. With A3 the same formula returns Socks instead of #N/A.
The last word: TEXTAFTER with -1
TEXTAFTER's third argument is the instance number, and -1 means "count from the end". So =TEXTAFTER(A2," ",-1) returns the text after the last space: XL.
The fifth argument, match_end, set to 1 treats the edges of the text as a delimiter. With it, a single-word cell returns the word itself instead of #N/A. A trailing space would make the last word empty, so TRIM matters here too.
Result: Socks
Socks. Without the 1 in the fifth argument this returns #N/A. For A2 it returns XL.
Any version: LEFT and FIND for the first word
FIND(" ",A2) is the position of the first space, and LEFT takes everything before it. The trick is &" ": adding a space to the end of the text guarantees FIND always finds one, so a single word like Socks returns Socks instead of #VALUE!.
This works in Excel 2010 through 365. For a leading space, use TRIM(A5) in both places.
Result: Socks
Socks. Without &" " the formula gives #VALUE! for one-word cells.
Any version: the last word with TRIM, SUBSTITUTE and REPT
There is no "find the last space" function in older Excel, so this trick pads the words apart instead. SUBSTITUTE replaces every space with 100 spaces. The last word is now alone in the last 100 characters, so RIGHT(…,100) grabs it with a lot of spaces in front, and TRIM throws those away.
100 works as long as no single word is longer than 100 characters. It is safe for single-word cells and extra spaces without any changes.
Result: Ivory
Ivory. The same pattern with LEFT instead of RIGHT returns the first word.
The nth word
Use the same padding with MID. Word n starts somewhere in the block of characters from (n-1)*100+1, so =TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),(3-1)*100+1,100)) returns the third word, Navy. Put the 3 in a cell to make it adjustable.
In Excel 365 or 2024, =INDEX(TEXTSPLIT(A2," "),3) is shorter. TEXTSPLIT splits at every space and INDEX picks one item. Ask for a word that does not exist, such as the fifth word of Silk Scarf Ivory, and INDEX returns #REF!; wrap it in IFERROR(…,"") if some rows are shorter.
Watch double spaces. A4 is "Wool Beanie Grey OS", so splitting at each space creates an empty item between Wool and Beanie and the third word becomes Beanie. TRIM the cell first, or set TEXTSPLIT's fourth argument (ignore_empty) to TRUE.
Result: Grey
Grey, the third word. Without the inner TRIM the double space shifts the words and the result is Beanie.
Which formula to use
On Excel 365 or 2024, TEXTBEFORE and TEXTAFTER read clearly and handle any delimiter; add the if_not_found or match_end argument for single-word cells. For files that must open in Excel 2019 or older, use LEFT with FIND for the first word and the SUBSTITUTE-REPT trick for the last and nth words.
If the words are people's names, the separate first and last name guide covers middle names and "Last, First" order. If you need every word in its own column, Data > Text to Columns with Space as the delimiter does it in one go.
Common mistakes
Forgetting single-word cells
TEXTBEFORE and TEXTAFTER give #N/A and LEFT/FIND gives #VALUE! when there is no space. Use the if_not_found argument, match_end, or the &" " trick.
Not trimming imported text
A leading space makes the first word empty and double spaces shift the nth word. Wrap the cell in TRIM before you split it.
Expecting punctuation to be removed
A description ending "Navy XL." returns "XL." with the full stop. Remove it with SUBSTITUTE before extracting.
Using a padding width shorter than the longest word
With REPT(" ",10), a word longer than 10 characters is cut short. 100 is a safe width for normal text.
FAQ
How do I extract the first word in Excel?
=TEXTBEFORE(A2," ") in Excel 365 or 2024, or =LEFT(A2,FIND(" ",A2&" ")-1) in any version. The second one also handles cells with only one word.
How do I get the last word in a cell?
=TEXTAFTER(A2," ",-1) in Excel 365 or 2024. In older versions use =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)).
How do I extract the second or third word?
=INDEX(TEXTSPLIT(TRIM(A2)," "),2) in Excel 365 or 2024. In any version, =TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",100)),(n-1)*100+1,100)) with n as the word number.
Why does my first-word formula return #N/A or #VALUE!?
The cell has no space, so there is nothing to split at. Give TEXTBEFORE a sixth argument with the value to return, or add &" " inside FIND.
Can I do this without a formula?
Yes. Flash Fill (Ctrl+E) learns the pattern from one or two examples you type, and Data > Text to Columns splits every word into its own column. Neither updates when the source changes.
Functions used
TEXTBEFOREText before a delimiterTEXTAFTERText after a delimiterTEXTSPLITSplits text into cells, spillsLEFTCharacters from the startRIGHTCharacters from the endMIDCharacters from the middleFINDPosition of text (case-sensitive)TRIMRemoves extra spacesSUBSTITUTEReplaces textREPTRepeats textINDEXValue at a positionIFERRORFallback when a formula errors
Related guides
- How to extract text before a character in Excel
- How to extract text after a character in Excel
- How to find the nth occurrence of a character in Excel
- How to separate first and last name in Excel
- How to split text by a delimiter in Excel
- How to extract the domain from an email address in Excel
- How to switch "Last, First" to "First Last" in Excel
Updated