Text function
MID function in Google Sheets and Excel
MID returns characters from the middle of a text: you say where to start and how many to take.
Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
Syntax
MID(text, start_num, num_chars)Arguments in [brackets] are optional. Google Sheets writes it MID(string, starting_at, extract_length).
Example
=MID(C2,4,2) reads: From C2 (GB-2041), start at the 4th character and take 2 characters.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Member code | City | Middle | |
| 2 | mara okafor | mara.okafor@example.com | GB-2041 | London | 20 |
| 3 | JONAS LIND | jonas.lind@example.org | SE-1187 | Malmö | |
| 4 | priya raman | priya.raman@example.net | IN-3302 | Pune | |
| 5 | Tomás Ruiz | tomas.ruiz@example.com | ES-0419 | Seville | |
| 6 | elif demir | elif.demir@example.org | TR-2750 | Izmir | |
| 7 | Kenji MORI | kenji.mori@example.net | JP-1093 | Osaka | |
| 8 | sofia rossi | sofia.rossi@example.com | IT-4468 | Turin | |
| 9 | Leo Brandt | leo.brandt@example.org | DE-3321 | Leipzig |
E2 shows 20: characters 4 and 5 of GB-2041 (G, B and - are positions 1 to 3).
How the spreadsheet calculates it
Takes 2 character(s) of C2, starting at character number 4.
- 1. MID: Takes
2character(s) ofC2, starting at character number4.text=`C2`: the cell to cut fromstart=`4`: the position of the first character to taken=`2`: how many characters to take
More MID examples
=MID(C2,4,4)All four digits of the member code: 2041.=MID(B2,FIND("@",B2)+1,100)Everything after the @: example.com.=MID(B2,FIND(".",B2)+1,FIND("@",B2)-FIND(".",B2)-1)The surname between the dot and the @: okafor.=VALUE(MID(C2,4,4))The digits as a number.
Paste any of these into the formula explainer to see it step by step.
Tips
- Count positions on paper first: the first character is 1, and spaces and punctuation count.
- Use FIND for start_num when the position varies.
- A generous num_chars (100) is a simple way to say "to the end".
What MID is used for
Pulling a part number, year or region code out of the middle of an ID, taking surnames from emails, and splitting fixed-width exports where each field always starts at the same position.
Arguments
| Argument | Required | What it is |
|---|---|---|
| text | Yes | The text or cell to cut from, such as C2. |
| start_num | Yes | The position of the first character to take; the first character is 1.Watch out: Past the end of the text MID returns empty text; less than 1 gives #VALUE!. |
| num_chars | Yes | How many characters to take. Asking for more than are left just returns the rest.Watch out: A negative number gives #VALUE!. |
Common mistakes
Counting from 0: the first character is position 1.
Leaving out num_chars: unlike LEFT and RIGHT, MID needs all three arguments.
Hard-coding the start position for texts of different lengths: find it with FIND, as in
MID(B2,FIND("@",B2)+1,100)for everything after the @.
In Google Sheets
Google Sheets has MID with the same three arguments, written MID(string, starting_at, extract_length); all three are required in both apps.
Errors you may see with MID
- #VALUE!: start_num is less than 1 or num_chars is negative, often because a FIND inside didn't find its character.
Questions
How do I extract the text between two characters?
Start one after the first character and take the distance to the second: =MID(B2,FIND(".",B2)+1,FIND("@",B2)-FIND(".",B2)-1) returns okafor from mara.okafor@example.com. More in extract text between two characters.
How do I take everything from a position to the end?
Give num_chars a number bigger than any text in the column, such as 100: MID stops at the end. Or use the exact count: LEN(C2)-3.
Why can't I add up MID's results?
MID always returns text, even when it looks like digits. Wrap it in VALUE: VALUE(MID(C2,4,4)) is the number 2041.
MID or TEXTAFTER?
TEXTAFTER (Excel 2024 and Microsoft 365) finds the cut by a delimiter instead of a position. MID with FIND works in every version and in Google Sheets.
Sources
Official documentation the facts on this page were checked against.