How to extract text before a character in Excel
Excel formula
=TEXTBEFORE(A2,$E$1)Use =TEXTBEFORE(A2,"-") in Excel 365. In any version, =LEFT(A2,FIND("-",A2)-1) returns everything before the first dash.
- Result on the example
- one result per row in
B2, filled down toB7 - Works in
- Excel 2024 and Microsoft 365
- Google Sheets
- Different formula, see below
See it work
The formula is already in B2, filled down to B7. Change any input and the result updates, or edit the formula to experiment.
How it works
TEXTBEFORE returns the text before the first occurrence of the delimiter. The classic version finds the delimiter's position with FIND and keeps one character less with LEFT, so the delimiter itself is dropped. Both work with any length of code before the dash.
=TEXTBEFORE(A2,$E$1)Result"NW"
A2"NW-2026-0142"The value in A2.
$E$1"-"The value in E1.
TEXTBEFORE(A2,$E$1)"NW"TEXTBEFORE: Text before a delimiter.- text
A2"NW-2026-0142" - delimiter
$E$1"-"
- text
In Google Sheets
Google Sheets needs a different formula: =LEFT(A2,FIND($E$1,A2)-1). On the same data it gives the same result. Here it is running in Google Sheets mode.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =LEFT(A2,FIND($E$1,A2)-1) | NW, SE, MIDWEST… | Works in every version of Excel and in Google Sheets. |
Common mistakes
- A cell without the delimiter returns #N/A from TEXTBEFORE (#VALUE! from FIND). Return the whole text instead:
=TEXTBEFORE(A2,$E$1,,,,A2). - Forgetting the
-1in the LEFT version keeps the dash: "NW-".
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Extract text before a character
B2, extract everything before the first delimiter in E1 and fill down to B7.Questions
How do I get the text before the last dash?
Use instance -1: =TEXTBEFORE(A2,"-",-1) returns "NW-2026".
How do I remove everything after a character?
That is the same formula: keeping the text before the character removes everything after it.
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.