Excel TEXTBEFORE
Grab everything before a comma, a space, or any delimiter — without the headache.
Wait, What Does TEXTBEFORE Even Do?
Okay, picture this: you’ve got a list of full names like “Smith, John” and you just want “Smith”. Or maybe you have email addresses like “jdoe@company.com” and you need the username before the @. In the old days, you’d use a mess of FIND, LEFT, and MID functions and pray you didn’t mess up the character count.
The Super Simple Syntax
You don’t need a PhD to use this thing. Here’s the basic setup:
That’s it. The text is whatever cell you’re pointing at, and the delimiter is the character (or characters) where you want to cut. If there’s no delimiter, it just gives you the whole text back — no drama.
Easy Warming Up with TEXTBEFORE
Example 1: Get the First Name from “First Last”
You’ve got a list of names where the first and last are separated by a space. You want just the first name.
=TEXTBEFORE(“Sarah Connor”, ” “) → “Sarah”
See? You tell it to cut at the space, and it hands you everything before that space. Easy peasy.
Example 2: Grab the Username from an Email
You have a column of email addresses like “alex.rivera@email.com” and you need just the username part.
=TEXTBEFORE(“mike@company.org”, “@”) → “mike”
One delimiter, one result. No more messing around with FIND and LEFT.
Example 3: What If There’s No Delimiter?
No worries — TEXTBEFORE just gives you the whole text back. It doesn’t throw a fit.
It just says, “hey, I didn’t find your comma, so here’s the whole thing.” No errors, no drama.
Medium Leveling Up
Example 1: The “Last, First” Problem (Last Name Only)
You know that annoying format where names are stored as “Last, First” and you need just the last name? TEXTBEFORE has your back.
=TEXTBEFORE(“Lee, Michelle”, “,”) → “Lee”
It grabs everything before the comma. If there’s a space after the comma, no problem — you’re getting the last name clean. If you wanted the first name, you’d use TEXTAFTER. But that’s a lesson for another day.
Example 2: Extract the Domain from a URL (kinda)
Let’s say you have a URL like “https://www.youtube.com/watch?v=abc123” and you want just “https://www.youtube.com”. You can cut at the third slash.
→ “https://www.youtube.com”
Whoa — there’s a third argument! That’s the instance number. It tells TEXTBEFORE to cut at the third slash. Without that, it would just stop at the first slash and give you “https:”. Not helpful. But with the 3, it skips the first two and cuts at the third.
Example 3: Pull the Product Code from “ID-Description”
You’ve got codes like “A45-BlackShoes” and you need just “A45”. The delimiter is “-“. Simple.
=TEXTBEFORE(“B12-RedHat”, “-“) → “B12”
If your product codes ever include multiple hyphens, you can use the instance number to grab the first, second, or third part. Super flexible.
Hard Now We’re Getting Fancy
Example 1: Match Mode — Case-Sensitive or Not?
By default, TEXTBEFORE is case-sensitive. That means “a” and “A” are different. But sometimes you don’t care about case. You can tell it to ignore case with the match_mode argument.
=TEXTBEFORE(“Eat APPLE pie”, “apple”) → “Eat APPLE pie”// Match mode = 1 means ignore case
=TEXTBEFORE(“Eat APPLE pie”, “apple”, , , 1) → “Eat “
See those empty commas? That’s where the instance number and other options would go. We’re skipping them to get to match_mode. The 1 at the end tells Excel “don’t be picky about case.” Super helpful when your data is messy.
Example 2: Handle Missing Delimiters with a Custom “Not Found” Message
What if the delimiter isn’t there? By default, it returns the whole text. But you might want it to say “N/A” or “Not Found” instead. There’s an argument for that: if_not_found.
→ “No comma found”
So now if there’s no comma, you get a friendly message instead of the whole text. Nice for reports where you want to flag missing data.
Example 3: Search from the End (Right-to-Left)
Sometimes you want to cut at the last occurrence of a delimiter. Like if you have a file path “C:\Users\John\Documents\file.txt” and you want the folder path before the last backslash. That’s where search_mode comes in. Set it to -1 to search from the end.
→ “C:\Users\John\Documents”
That -1 tells Excel “start looking from the right side and find the first backslash you see.” That gives you everything before the last backslash — the folder path. Without that, you’d get “C:” which is not what you want.
Cheat Sheet: TEXTBEFORE Arguments
Here’s the full list of arguments in order. Don’t memorize them — just know they exist when you need them.
| Argument | What It Does |
|---|---|
text |
The text you’re cutting from. Required. |
delimiter |
The character(s) where you cut. Required. |
instance_num |
Which occurrence to cut at. Default = 1 (first). Use 2 for second, etc. |
match_mode |
0 = case-sensitive (default), 1 = ignore case. |
if_not_found |
What to return if delimiter isn’t found. Default = the whole text. |
search_mode |
1 = search from left (default), -1 = search from right (last occurrence). |
match_mode, just use empty commas like =TEXTBEFORE(text, delimiter, , , 1).Oops — Stuff You’ll Probably Mess Up (And That’s Okay)
- Forgetting the delimiter is case-sensitive by default. If you’re looking for “apple” and the text has “Apple”, it won’t find it. Use match_mode = 1 to ignore case.
- Using the wrong instance number. You want the third slash, but you put 2? You’ll get something unexpected. Count your delimiters.
- Expecting it to work with numbers. TEXTBEFORE is for text. If you feed it a number, Excel will convert it to text, but it might not behave the way you expect.
- Not knowing if the delimiter exists. If you’re not sure, use the if_not_found argument to catch it gracefully.
- Confusing TEXTBEFORE with TEXTAFTER. They’re siblings. TEXTBEFORE gives you the left side. TEXTAFTER gives you the right side. Both are awesome.
Your Turn — Try These
Open Excel (or Google Sheets — it has TEXTBEFORE too!) and try these out. You’ll get the hang of it in like 5 minutes.
- First word from “Hello World” — delimiter is space. Should return “Hello”.
- City from “New York, NY” — delimiter is comma. Should return “New York”.
- Second part from “A-B-C-D” — delimiter is hyphen, instance_num = 2. Should return “A-B”.
- Folder from “C:\Users\John\file.txt” — delimiter is backslash, search_mode = -1. Should return “C:\Users\John”.
- “No delimiter here” with a comma — use if_not_found to return “Missing delimiter”.
If you can do all five without peeking at the answers, you’ve officially mastered TEXTBEFORE. And honestly, that’s a solid skill to have in your back pocket.

Leave a Reply
You must be logged in to post a comment.