Splitting text used to mean complicated formulas with LEFT, FIND and MID. Newer versions of Excel have three functions that make it simple: TEXTBEFORE, TEXTAFTER and TEXTSPLIT.
Works in: Excel for Microsoft 365, Excel 2024 and Excel for the web.
TEXTBEFORE: everything before a character
=TEXTBEFORE(A2, " ")
| A2 | Formula | Result |
|---|---|---|
| Sara Ali | =TEXTBEFORE(A2," ") |
Sara |
| sara@company.com | =TEXTBEFORE(A2,"@") |
sara |
| INV-2026-0042 | =TEXTBEFORE(A2,"-") |
INV |
TEXTAFTER: everything after a character
=TEXTAFTER(A2, "@")
| A2 | Formula | Result |
|---|---|---|
| sara@company.com | =TEXTAFTER(A2,"@") |
company.com |
| Sara Ali Hassan | =TEXTAFTER(A2," ",-1) |
Hassan (after the last space) |
| INV-2026-0042 | =TEXTAFTER(A2,"-",2) |
0042 (after the 2nd dash) |
Tip: the third argument chooses which occurrence. Negative numbers count from the end, so -1 means the last one.
TEXTSPLIT: split into separate cells
=TEXTSPLIT(A2, ", ")
If A2 is Red, Blue, Green, the result spills into three cells: Red | Blue | Green.
- Split into rows instead of columns:
=TEXTSPLIT(A2,,", ")(leave the column delimiter empty). - Several delimiters:
=TEXTSPLIT(A2,{",",";"," "}) - Ignore empty values: set the 4th argument to TRUE:
=TEXTSPLIT(A2,",",,TRUE)
Make sure the cells to the right are empty, or you’ll get a #SPILL! error. See Excel errors explained.
Handle missing delimiters
If the text doesn’t contain the delimiter, TEXTBEFORE/TEXTAFTER return #N/A. Add a fallback with the last argument:
=TEXTBEFORE(A2," ",,,,A2)
This returns the whole text when there’s no space (for one-word names).
Practical examples
| Task | Formula |
|---|---|
| First name | =TEXTBEFORE(A2," ") |
| Last name | =TEXTAFTER(A2," ",-1) |
| Email domain | =TEXTAFTER(A2,"@") |
| Text inside brackets | =TEXTBEFORE(TEXTAFTER(A2,"("),")") |
| File extension | =TEXTAFTER(A2,".",-1) |
Clean extra spaces first with TRIM. For more name examples, see how to split first and last names.
Get the last part with a negative instance
All three functions take an optional instance number. A negative number counts from the end of the text, which is perfect for file names and full names with middle names:
| A2 | Formula | Result |
|---|---|---|
| Sara Mohammed Ali | =TEXTAFTER(A2," ",-1) |
Ali (last word) |
| Sara Mohammed Ali | =TEXTBEFORE(A2," ",-1) |
Sara Mohammed |
| Report.final.v2.xlsx | =TEXTAFTER(A2,".",-1) |
xlsx (file extension) |
| INV-2026-0042 | =TEXTBEFORE(A2,"-",2) |
INV-2026 |
Ignore capital letters: the fourth argument (match mode) set to 1 makes the delimiter case-insensitive, for example =TEXTAFTER(A2,"x",,1) treats “x” and “X” the same.
Real tasks you can solve in one formula
| Task | A2 example | Formula | Result |
|---|---|---|---|
| Company domain from an email | omar@gulfsupplies.com | =TEXTBEFORE(TEXTAFTER(A2,"@"),".") |
gulfsupplies |
| Area code from a phone number | +973-1712-3456 | =TEXTBEFORE(TEXTAFTER(A2,"+"),"-") |
973 |
| Folder from a file path | D:\Reports\2026\Sales.xlsx | =TEXTBEFORE(A2,"\",-1) |
D:\Reports\2026 |
| Split a full address into columns | Building 12, Road 45, Manama | =TEXTSPLIT(A2,", ") |
Building 12 | Road 45 | Manama |
| Text between brackets | Laptop (Dell 14″) | =TEXTBEFORE(TEXTAFTER(A2,"("),")") |
Dell 14″ |
Tip: nesting TEXTBEFORE inside TEXTAFTER is the easiest way to get “the text between two characters”, something that used to need MID and two FIND functions.
Common mistakes
- Spilled results get blocked. TEXTSPLIT returns several cells. If any of them already contain data you get
#SPILL!. Clear the cells to the right (or below). - The result is text, not a number. Splitting “INV-2026” gives the text “2026”. Wrap it in
VALUE()or add--in front if you need to calculate with it. - Extra spaces. Splitting on “,” leaves a space at the start of each part. Split on “, ” (comma and space) or wrap the result in
TRIM(). See TRIM, CLEAN and PROPER. - Sharing with older Excel. Colleagues on Excel 2019 or older see
#NAME?. Convert the results to values (Copy → Paste Values) before you send the file.
Older Excel and Google Sheets
- Older Excel: use Data → Text to Columns, Flash Fill (Ctrl + E), or LEFT/FIND formulas:
=LEFT(A2,FIND(" ",A2)-1). - Google Sheets: use
=SPLIT(A2,",")or REGEXEXTRACT. See the Google Sheets cheat sheet.
Quick summary
- TEXTBEFORE = text before a character. TEXTAFTER = text after it.
- Use -1 for the last occurrence (great for last names and file types).
- TEXTSPLIT splits text into multiple cells or rows.
FAQ
Which Excel versions have TEXTSPLIT, TEXTBEFORE and TEXTAFTER?
Excel for Microsoft 365, Excel 2024 and Excel for the web. In older versions use LEFT, MID, RIGHT and FIND, or Data → Text to Columns.
How do I split text into rows instead of columns?
Use the third argument of TEXTSPLIT, the row delimiter. For example =TEXTSPLIT(A2,,”, “) puts each comma-separated item on its own row.
How do I get the text after the last space in Excel?
Use =TEXTAFTER(A2,” “,-1). The -1 tells Excel to use the last space instead of the first.
What happens if the delimiter is not found?
TEXTBEFORE and TEXTAFTER return #N/A. Add the last argument to show something else, for example =TEXTAFTER(A2,”@”,,,,”No email”).