# How to extract text between two characters in Excel

Take the text after the first character, then the text before the second: =TEXTBEFORE(TEXTAFTER(A2,"@"),".").

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

**Google Sheets:** `=MID(A2,FIND($E$1,A2)+1,FIND($G$1,A2,FIND($E$1,A2)+1)-FIND($E$1,A2)-1)`

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F | G |
| --- | --- | --- | --- | --- | --- | --- |
| Email | Company |  | Start after | @ | End before | . |
| lena.park@northwind.example |  |  |  |  |  |  |
| omar@contoso.example |  |  |  |  |  |  |
| p.shah@fabrikam.example |  |  |  |  |  |  |
| tom.becker@litware.example |  |  |  |  |  |  |
| ines@adatum.example |  |  |  |  |  |  |

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

Result: northwind; contoso; fabrikam; litware; adatum

## How it works

TEXTAFTER cuts off everything up to the @, leaving "northwind.example". TEXTBEFORE then keeps what comes before the next dot. Because the second search runs on what is left, the dot in "lena.park" never gets in the way.

The MID version does the same with positions: start one character after the @, and search for the dot starting from the @ (FIND's third argument).

## Other ways

- `=MID(A2,FIND($E$1,A2)+1,FIND($G$1,A2,FIND($E$1,A2)+1)-FIND($E$1,A2)-1)`: Works in every version and in Google Sheets. The length is the end position minus the start position, minus one.

## Common mistakes

- Searching for the dot from the start of the text finds the one in "lena.park", before the @, and MID gets a negative length. Start the second FIND after the first character.
- If either character is missing you get #N/A or #VALUE!. Wrap the formula in `IFERROR(…,"")`.

## Questions

**How do I extract text between two words?**

Use the words as delimiters: `=TEXTBEFORE(TEXTAFTER(A2,"from ")," to")`.

**How do I get the text between the second and third dash?**

Give TEXTAFTER an instance number: `=TEXTBEFORE(TEXTAFTER(A2,"-",2),"-")`.

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-between-two-characters
