# How to extract text before a character in Excel

Use =TEXTBEFORE(A2,"-") in Excel 365. In any version, =LEFT(A2,FIND("-",A2)-1) returns everything before the first dash.

**Excel:** `=TEXTBEFORE(A2,$E$1)` (Excel 2024 and Microsoft 365)

**Google Sheets:** `=LEFT(A2,FIND($E$1,A2)-1)`

## Example

Sample data (row 1 is the header):

| A | B | C | D | E |
| --- | --- | --- | --- | --- |
| Order code | Region code |  | Delimiter | - |
| NW-2026-0142 |  |  |  |  |
| SE-2026-0087 |  |  |  |  |
| MIDWEST-2025-1120 |  |  |  |  |
| W-2026-0031 |  |  |  |  |
| NE-2026-0256 |  |  |  |  |
| INTL-2024-0009 |  |  |  |  |

Formula in B2, filled to B7: `=TEXTBEFORE(A2,$E$1)`

Result: NW; SE; MIDWEST; W; NE; INTL

## 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.

## Other ways

- `=LEFT(A2,FIND($E$1,A2)-1)`: 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 `-1` in the LEFT version keeps the dash: "NW-".

## 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.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/extract-text-before-a-character
