formulastreak

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

The area code sits between the first and second space of each phone number · edit F2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultF2 = 20
ABCDEF
1CustomerPhoneOrderAmountCityArea code
2Okafor, Mara+44 20 7946 0321ORD-2026-0412$1,250.00London 20
3Lind, Jonas+46 40 123 456ORD-2026-0413$89.90Malmö40
4Raman, Priya+91 20 5550 1234ORD-2026-0419$2,040.00 Pune20
5Ruiz, Tomás+34 954 000 111ORD-2026-0420$15.00Seville 954
6Demir, Elif+90 232 555 0199ORD-2026-0425$310.50Izmir232
7Mori, Kenji+81 6 5550 7788ORD-2026-0431$799.00Osaka  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. 1. FIND: Finds where " " first appears in B2, as a character position (1 = the first character). It's case-sensitive and gives #VALUE! if it isn't there.
  2. 2. FIND: Finds where " " first appears in B2, as a character position (1 = the first character). It's case-sensitive and gives #VALUE! if it isn't there.
  3. 3. FIND: Finds where " " first appears in B2, as a character position (1 = the first character). It's case-sensitive and gives #VALUE! if it isn't there.
  4. 4. FIND: Finds where " " first appears in B2, as a character position (1 = the first character). It's case-sensitive and gives #VALUE! if it isn't there.
  5. 5. MID: Takes (the result of step 3 minus the result of step 4) minus 1 character(s) of B2, starting at character number the result of step 1 plus 1.

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.

Practise MID on a live sheet

Lesson 31, Split names and codes (Unit 8, Cleaning text at scale), has 5 graded exercises, checked instantly, with steps and hints when you're stuck. Pro