Cellwise Try it free

Excel guide · 3 min read

How to extract text before a character in Excel

Quick answerIn Excel 365, use =TEXTBEFORE(A2,"@") to return everything before the first @. In any version, =LEFT(A2,FIND("@",A2)-1) does the same: FIND locates the character and LEFT keeps everything to its left.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

ABC
1EmailItem codeLocation
2jsmith@contoso.comTSH-RED-LPortland, OR
3kate.lee@fabrikam.comMUG-BLU-12Tampa, FL
4dev@adatum.ioCAP-BLK-OSReno, NV
5mgarcia@tailspin.netBAG-GRN-XLMadison, WI

Method 1: TEXTBEFORE (Excel 365 and 2024)

TEXTBEFORE takes the text and the delimiter, and returns what comes before the first match. It is short, readable and easy to adjust. Fill it down the column and every email gives up its username.

Because it is a formula, the result updates whenever the source cell changes. That makes it a better fit than Text to Columns for lists that keep growing.

=TEXTBEFORE(A3,"@")

Result: kate.lee

Returns "kate.lee", the username part of the email.

Text before a multi-character delimiter

The delimiter can be longer than one character. Use ", " to split a city from its state without leaving a stray comma behind.

=TEXTBEFORE(C4,", ")

Result: Reno

Returns "Reno".

Method 2: LEFT and FIND (every version)

FIND returns the position of the character. Subtract 1 so you stop just before it, and LEFT returns that many characters from the start.

Use SEARCH instead of FIND if you need a case-insensitive match for letters. FIND is case-sensitive.

=LEFT(B2,FIND("-",B2)-1)

Result: TSH

Returns "TSH". FIND gives 4 for the first dash, so LEFT keeps 3 characters.

And the text after the character

TEXTAFTER is the mirror image. In older Excel, use =MID(A2,FIND("@",A2)+1,100) to start one character after the delimiter and take the rest.

=TEXTAFTER(A5,"@")

Result: tailspin.net

Returns "tailspin.net".

Before the last or second occurrence

TEXTBEFORE has a third argument, instance_num. =TEXTBEFORE(B3,"-",2) returns "MUG-BLU", the text before the second dash. A negative number counts from the end, so =TEXTBEFORE(B3,"-",-1) also returns everything before the last dash, however many dashes there are.

In any version, you can get the same result by nesting FIND. The inner FIND locates the first dash, and the outer FIND starts searching one character after it, so it lands on the second dash. LEFT then keeps everything before that.

Getting the very last occurrence in older Excel needs a much longer SUBSTITUTE formula. If you can, use TEXTBEFORE or split the column with Data > Text to Columns.

=LEFT(B3,FIND("-",B3,FIND("-",B3)+1)-1)

Result: MUG-BLU

Returns "MUG-BLU", the item and colour without the size.

Common mistakes

Forgetting the -1

=LEFT(A2,FIND("@",A2)) includes the @ itself. Subtract 1 to stop before it.

#VALUE! when the character is missing

Both FIND and TEXTBEFORE fail if the delimiter is not there. Use TEXTBEFORE's if_not_found argument, =TEXTBEFORE(A2,"@",,,,A2), or wrap the formula in IFERROR.

FIND is case-sensitive

FIND("x",A2) will not find "X". Use SEARCH for letters when case should not matter.

#NAME? from TEXTBEFORE

Your version does not have it. Use LEFT and FIND, which work in every version.

FAQ

How do I extract text before a space in Excel?

Use =TEXTBEFORE(A2," ") or =LEFT(A2,FIND(" ",A2)-1). This is how you pull a first name out of a full name.

How do I get the text before a comma?

Use =TEXTBEFORE(A2,","). If the comma is followed by a space you also want to drop on the other side, use TEXTAFTER(A2,", ") for the right-hand part.

Can I do this without a formula?

Yes. Data > Text to Columns with your character as the delimiter splits the column, or type the first result and press Ctrl+E for Flash Fill.

Which is better, TEXTBEFORE or LEFT with FIND?

TEXTBEFORE is easier to read and has built-in options for the nth occurrence and a not-found value. LEFT with FIND works in every version, so use it in files you share with people on older Excel.

Does TEXTBEFORE work in Excel 2021?

No. TEXTBEFORE and TEXTAFTER are in Excel for Microsoft 365, Excel for the web and Excel 2024. Use LEFT with FIND in Excel 2021 and earlier.

Functions used

Related guides

Updated