Text function

MID function

Returns a given number of characters from the middle of a text, starting at any position you choose.

Available in All versions of Excel, including Microsoft 365, Excel for Mac and Excel for the web

In every Excel versionWorks in Google Sheets

Syntax

MID(text, start_num, num_chars)
ArgumentWhat it means
textRequiredThe text or cell to take characters from.
start_numRequiredPosition of the first character to return (1 = first character).
num_charsRequiredHow many characters to return. If it runs past the end, MID stops at the end.

Returns: Text: the extracted characters.

How MID works

MID extracts a slice from anywhere in a text. You tell it where to start and how many characters to take: =MID("PRD-2026-0458",5,4) returns 2026. It is the general-purpose cutting tool; LEFT and RIGHT are just shortcuts for slices at the start and end.

For data with a fixed layout - dates stored as 20260315, account numbers, tax IDs - MID with fixed numbers is all you need. For variable layouts, calculate start_num with FIND or SEARCH, e.g. start one character after the @ of an email to get the domain. If you do not know how many characters remain, simply give a large num_chars such as 100: MID will stop at the end of the text without complaint.

MID returns text, so digits you extract need VALUE (or DATE for date parts) before calculating. If start_num is beyond the end of the text, MID returns an empty string rather than an error.

Examples

1Year from a product code

B2fx=MID(A2,5,4)
AB
1Product code
2PRD-2026-04582026

Result: 2026

Starting at character 5 (after PRD-), MID takes 4 characters.

2Domain from an email address

B2fx=MID(A2,FIND("@",A2)+1,100)
AB
1Email
2[email protected]contoso.com

Result: contoso.com

FIND returns 10, so MID starts at 11. Asking for 100 characters simply returns everything to the end.

3Turn yyyymmdd text into a real date

B2fx=DATE(LEFT(A2,4),MID(A2,5,2),RIGHT(A2,2))
AB
1Date (text)
2202603152026-03-15

Result: 2026-03-15

MID takes the month 03 from positions 5-6. DATE turns year, month and day into the serial number 46096, shown here with a yyyy-mm-dd format.

4Start past the end

B2fx=MID(A2,5,3)
AB
1Code
2AB

Result:

The text has only 2 characters, so there is nothing at position 5. MID returns an empty string, not an error.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 17 KB

Common errors and how to fix them

ErrorWhy it happensFix
#VALUE!start_num is less than 1, or num_chars is negative.Check the FIND/SEARCH calculation that produces them; wrap in IFERROR when a delimiter may be missing.

Tips

  • In Microsoft 365 =MID(A2,SEQUENCE(LEN(A2)),1) splits a text into single characters, one per row.
  • To get the text between two delimiters, TEXTBEFORE and TEXTAFTER nest more readably: =TEXTBEFORE(TEXTAFTER(A2,"-"),"-").
  • MID cannot be used on the left of = to change part of a cell; use REPLACE for that.

Questions

How do I extract text between two characters?

Find both positions with FIND and use MID: =MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1) returns what is inside brackets. In Microsoft 365 =TEXTBEFORE(TEXTAFTER(A2,"("),")") is simpler.

Why does MID return numbers that SUM ignores?

MID always returns text. Use =VALUE(MID(...)) or =--MID(...) to convert the result to a number.

Google Sheets

MID also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

MID in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
CzechČÁST
DanishMIDT
DutchDEEL
FinnishPOIMI.TEKSTI
FrenchSTXT
GermanTEIL
HungarianKÖZÉP
ItalianSTRINGA.ESTRAI
Norwegian (Bokmål)DELTEKST
PolishFRAGMENT.TEKSTU
Portuguese (Brazil)EXT.TEXTO
Portuguese (Portugal)SEG.TEXTO
RussianПСТР
SpanishEXTRAE
SwedishEXTEXT
TurkishPARÇAAL

Recipes that use MID