TEXTBEFORE and TEXTAFTER are new Excel 365 functions that allow you to extract text parts easily. These functions are easy to use and return complex extraction like what FlashFill can do.
They can efficiently extract names, first names, cities, zip codes, and addresses from text.
![How to extract text with TEXTAFTER and TEXTBEFORE](https://excel-tutorial.com/wp-content/uploads/2022/08/Table-clients-and-addresses.png)
Extract the first word of a string.
The TEXTBEFORE function returns text that occurs before a given character or string, like a space.
Extract the first word from a text
To extract the first word, write =TEXTBEFORE(A2," ")
.
![Extract the first word of the cells](https://excel-tutorial.com/wp-content/uploads/2022/08/Extract-the-first-word-of-the-cells.png)
It is simple: you extract the text BEFORE the first delimiter.
Extract the first two words
TEXTBEFORE has a third argument that specifies how many words to extract.
To extract the name and surname, use =TEXTBEFORE(A2," ",2)
.
![Extract Name and Firstname](https://excel-tutorial.com/wp-content/uploads/2022/08/Extract-Name-and-Firstname.png)
Using LEFT and SEARCH, you would need a complex formula. So TEXTBEFORE is straightforward to use 😉
=LEFT(A2,SEARCH(" ",A2,SEARCH(" ",A2,1)+1))
The TEXTAFTER function
The TEXTAFTER function extracts text after the nth delimiter.
To return the address, postal code, and city, we must extract the string after the second "space". So the formula is =TEXTAFTER(A2," ",2)
.
![TEXTAFTER the second space](https://excel-tutorial.com/wp-content/uploads/2022/08/TEXTAFTER-the-second-space.png)
Use negative value
TEXTAFTER and TEXTBEFORE allow negative values, and this is super useful. A negative value means you read your string from the right 😮👍
For instance, to extract the City name, that means the word after the last comma of the string, we will write the formula : TEXTAFTER(A2,",",-1)
![Negative value to extract from the right of the string](https://excel-tutorial.com/wp-content/uploads/2024/11/Negative-value-to-extract-from-the-right-of-the-string.png)
How do you extract a substring in the middle?
To extract only the name, you combine both functions.
- First, TEXTBEFORE extracts the first two words.
- Then, TEXTAFTER extracts the last word from that result.
=TEXTAFTER(TEXTBEFORE(A2," ",2)," ")
![Extract the name only](https://excel-tutorial.com/wp-content/uploads/2022/08/Extract-the-name-only.png)
Another example is how to extract the address only. You can do it with these steps.
- Remove the name and surname using a space delimiter.
- Remove the last two words using a comma delimiter.
=TEXTBEFORE(TEXTAFTER(A2," ",2),",",-2)
![Extract the address only](https://excel-tutorial.com/wp-content/uploads/2022/08/Extract-the-address-only.png)