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)| Argument | What it means | |
|---|---|---|
text | Required | The text or cell to take characters from. |
start_num | Required | Position of the first character to return (1 = first character). |
num_chars | Required | How 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
| A | B | |
|---|---|---|
| 1 | Product code | |
| 2 | PRD-2026-0458 | 2026 |
Result: 2026
Starting at character 5 (after PRD-), MID takes 4 characters.
2Domain from an email address
| A | B | |
|---|---|---|
| 1 | ||
| 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
| A | B | |
|---|---|---|
| 1 | Date (text) | |
| 2 | 20260315 | 2026-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
| A | B | |
|---|---|---|
| 1 | Code | |
| 2 | AB |
Result:
The text has only 2 characters, so there is nothing at position 5. MID returns an empty string, not an error.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#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.
| Language | Function name |
|---|---|
| Czech | ČÁST |
| Danish | MIDT |
| Dutch | DEEL |
| Finnish | POIMI.TEKSTI |
| French | STXT |
| German | TEIL |
| Hungarian | KÖZÉP |
| Italian | STRINGA.ESTRAI |
| Norwegian (Bokmål) | DELTEKST |
| Polish | FRAGMENT.TEKSTU |
| Portuguese (Brazil) | EXT.TEXTO |
| Portuguese (Portugal) | SEG.TEXTO |
| Russian | ПСТР |
| Spanish | EXTRAE |
| Swedish | EXTEXT |
| Turkish | PARÇAAL |
Recipes that use MID
- How to capitalize the first letter in Excel
- How to convert text to a date in Excel
- How to extract numbers from text in Excel
- How to extract text between two characters in Excel
- How to split first and last name in Excel