Cellwise Try it free

Cleanup function

Excel TEXTBEFORE function

TEXTBEFORE returns everything in a text string before a character or word you choose. Use it to pull usernames out of emails, first names out of full names, or prefixes out of product codes.

=TEXTBEFORE(text, delimiter)

Arguments

text
The text to split, usually a cell.
delimiter
The character or text to stop at, in quotes.

TEXTBEFORE examples

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

ABC
1EmailNameSKU
2maria.lopez@northwind.comMaria LopezTSH-BLU-M
3dev.patel@harborfoods.orgDev PatelMUG-WHT-12
4kim@lakeside.ioKim NgCAP-BLK
  1. =TEXTBEFORE(A2,"@")

    Result: maria.lopez

    Returns the username: maria.lopez.

  2. =TEXTBEFORE(B3," ")

    Result: Dev

    Everything before the first space is the first name, Dev.

  3. =TEXTBEFORE(C3,"-")

    Result: MUG

    Pulls the product family code, MUG, from the SKU.

  4. =TEXTBEFORE(B4,",")

    Result: #N/A

    There is no comma in the name, so you get #N/A.

  5. =IFERROR(TEXTBEFORE(B4,","),B4)

    Result: Kim Ng

    Wrap it in IFERROR to fall back to the full text.

How to use TEXTBEFORE

  1. Click the cell for the result.
  2. Type =TEXTBEFORE( and click the text cell.
  3. Type a comma and the delimiter in quotes.
  4. Press Enter, then fill down.

Common TEXTBEFORE mistakes

Getting #N/A

The delimiter is not in the text. Add an if_not_found value as the sixth argument, or wrap it in IFERROR.

Using it in older Excel

TEXTBEFORE is in Microsoft 365, Excel 2024 and Excel for the web. In older versions use LEFT with FIND.

Case does not match

The match is case-sensitive by default. Set match_mode, the fourth argument, to 1 to ignore case.

TEXTBEFORE FAQ

How do I extract text before a character in Excel?

Use =TEXTBEFORE(A2,"-"). In older Excel, use =LEFT(A2,FIND("-",A2)-1).

How do I get the first name from a full name in Excel?

Use =TEXTBEFORE(A2," ") to take everything before the first space.

How do I get text before the second dash?

Add the instance number as the third argument: =TEXTBEFORE(A2,"-",2).

Practice TEXTBEFORE in these lessons

Guides that use TEXTBEFORE

Related functions

Updated