Extract text between two characters in Excel (substring)
Updated · Checked on a live sheet · Excel and Google Sheets
The formula
To get the substring between two characters in Excel, find both characters with FIND and take the text between them with MID: =MID(B2, FIND(" ", B2)+1, FIND(" ", B2, FIND(" ", B2)+1) - FIND(" ", B2) - 1) returns the text between the first and second space. FIND locates both spaces; MID takes the characters between them. Swap the space for any character, such as "-" or "(".
In general: =MID(text, FIND(char, text)+1, FIND(char, text, FIND(char, text)+1) - FIND(char, text) - 1)
Try it on a live sheet
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Customer | Phone | Order | Amount | City | Area code |
| 2 | Okafor, Mara | +44 20 7946 0321 | ORD-2026-0412 | $1,250.00 | London | 20 |
| 3 | Lind, Jonas | +46 40 123 456 | ORD-2026-0413 | $89.90 | Malmö | 40 |
| 4 | Raman, Priya | +91 20 5550 1234 | ORD-2026-0419 | $2,040.00 | Pune | 20 |
| 5 | Ruiz, Tomás | +34 954 000 111 | ORD-2026-0420 | $15.00 | Seville | 954 |
| 6 | Demir, Elif | +90 232 555 0199 | ORD-2026-0425 | $310.50 | Izmir | 232 |
| 7 | Mori, Kenji | +81 6 5550 7788 | ORD-2026-0431 | $799.00 | Osaka | 6 |
F2 shows 20 for Mara's +44 20 7946 0321: the characters between the first and the second space.
Why it works
Takes (the position of " " in B2 minus the position of " " in B2) minus 1 character(s) of B2, starting at character number the position of " " in B2 plus 1.
- 1. FIND: Finds where
" "first appears inB2, as a character position (1 = the first character). It's case-sensitive and gives#VALUE!if it isn't there. - 2. FIND: Finds where
" "first appears inB2, as a character position (1 = the first character). It's case-sensitive and gives#VALUE!if it isn't there. - 3. FIND: Finds where
" "first appears inB2, as a character position (1 = the first character). It's case-sensitive and gives#VALUE!if it isn't there. - 4. FIND: Finds where
" "first appears inB2, as a character position (1 = the first character). It's case-sensitive and gives#VALUE!if it isn't there. - 5. MID: Takes (the result of step 3 minus the result of step 4) minus
1character(s) ofB2, starting at character number the result of step 1 plus1.
Between two different characters
For text between a hyphen and the next hyphen, as in order numbers like ORD-2026-0412, use "-" in all three FINDs: MID(C2, FIND("-", C2)+1, FIND("-", C2, FIND("-", C2)+1) - FIND("-", C2) - 1) returns the year.
=MID(C2,FIND("-",C2)+1,FIND("-",C2,FIND("-",C2)+1)-FIND("-",C2)-1)TEXTBEFORE and TEXTAFTER (Excel 2024, Microsoft 365)
Take what's after the first delimiter, then what's before the next one: TEXTBEFORE(TEXTAFTER(B2, " "), " "). Much easier to read, but not available in Google Sheets or older Excel.
=TEXTBEFORE(TEXTAFTER(B2," ")," ")When you need it
Codes and identifiers often carry information in the middle: an area code inside a phone number, a year inside an order number, a department code inside an employee ID, a value inside brackets in a product description. Extracting it into its own column lets you sort, filter and total by it. Check a few rows by eye afterwards: one record with a missing or extra delimiter is enough to throw the positions off, and those are exactly the rows worth fixing at the source.
In Google Sheets
MID and FIND work the same in Google Sheets. TEXTBEFORE and TEXTAFTER don't exist there; SPLIT can break the text into parts instead, and INDEX picks the part you want.
Common mistakes
Forgetting the third argument of the second FIND (where to start searching), so it finds the first character again.
Off-by-one lengths: subtract 1 so neither delimiter is included.
Text without the second delimiter, which gives #VALUE!; wrap the formula in IFERROR if some rows can lack it.
Sources
Official documentation the facts on this page were checked against.