Use =MID(A2,3,8) to pull characters out of the middle of a cell: take the text in A2, start at character 3, and keep 8 characters. On the waybill "WB20261103JNBCPT0042" it returns "20261103". MID needs all three arguments, and the start position counts from 1. When the start moves from row to row, let FIND work it out.
Functions
Excel MID Function: Extract Text From the Middle
Ready to practice?
Apply what you just learned with interactive exercises.
This page explains what MID does in Excel, then works through fixed-width codes, text between brackets, what happens past the end of the text, and the newer functions that sometimes replace it.
TL;DR
- =MID(text, start_num, num_chars) returns num_chars characters beginning at position start_num. All three arguments are required.
- Position 1 is the first character. =MID(A2,3,8) starts at the third character, not after it.
- Pair MID with FIND to take text between two markers: =MID(B2,FIND("(",B2)+1,FIND(")",B2)-FIND("(",B2)-1).
- Starting past the end returns empty text, and asking for too many characters just stops at the end. A start of 0 or a negative length returns #VALUE!.
- The result is text, even if it looks like a number. Wrap it in VALUE before you calculate.
- In Microsoft 365 and Excel 2024, TEXTBEFORE and TEXTAFTER can replace MID with FIND for delimited text.
Table of Contents
- Sample data used on this page
- MID syntax
- What does MID do in Excel
- Cut a fixed-width code into parts
- Turn extracted pieces into a date or a number
- MID and FIND function in Excel
- Get a first name from Surname, First Name
- What MID does when you run past the end
- MID with TEXTBEFORE, TEXTAFTER and TEXTSPLIT
- Test or count rows with MID
- MID compared with its alternatives
- Excel versions that have MID
- MID errors and their fixes
- What learners get wrong
- Worked scenario: break a courier export into columns
- Practice MID in the lessons
- FAQ
- Sources
Sample data used on this page
The examples use a courier's waybill list. Column A holds a 20-character waybill with a fixed layout: "WB", then the ship date as year, month and day (8 digits), then the origin hub (3 letters), the destination hub (3 letters) and a 4-digit sequence number. Column B holds the contact for each parcel as "Surname, First name (Department)". Row 1 holds the headers.
| Row | A (Waybill) | B (Contact) |
| 2 | WB20261103JNBCPT0042 | Dlamini, Sipho (Finance) |
| 3 | WB20261029DURJNB0107 | Pillay, Anika (Operations) |
| 4 | WB20261030CPTPLZ0015 | van Wyk, Johan (Sales) |
| 5 | WB20261101JNBDUR0230 | Naidoo, Kavita (HR) |
| 6 | WB20261102PLZCPT0009 | Mokoena, Thandi (Finance) |
| Part | Positions | Length |
| Prefix "WB" | 1 to 2 | 2 |
| Ship date | 3 to 10 | 8 |
| Origin hub | 11 to 13 | 3 |
| Destination hub | 14 to 16 | 3 |
| Sequence | 17 to 20 | 4 |
MID syntax
=MID(text, start_num, num_chars)
| Argument | Required? | What it does |
| text | Required | The text to read from. A cell reference, quoted text or a formula result. |
| start_num | Required | The position of the first character to return. 1 is the first character of the text. |
| num_chars | Required | How many characters to return, counting from start_num. |
What does MID do in Excel
MID returns a slice of text from the middle. Think of it as LEFT with a movable start. =LEFT(A2,10) always begins at the first character, while =MID(A2,3,8) begins at any position you name.
On A2 the formula =MID(A2,3,8) returns "20261103". It skipped "WB", started at character 3, and kept eight. The same function covers the two edges as well. =MID(A2,1,2) behaves like =LEFT(A2,2) and returns "WB". Use MID when neither end of the text is where you want to begin.
A quick way to avoid off-by-one mistakes is to say the formula out loud: "start at character 3 and take 8". If the first thing you want is the Nth character, start_num is N, not N minus 1. A start of 2 on A2 gives =MID(A2,2,8), which returns "B2026110", because it begins at the "B".
Cut a fixed-width code into parts
When every code has the same layout, hard-coded positions are all you need. Using the position map above:
| Part | Formula | Result on A2 |
| Ship date | =MID(A2,3,8) | 20261103 |
| Origin hub | =MID(A2,11,3) | JNB |
| Destination hub | =MID(A2,14,3) | CPT |
| Sequence | =MID(A2,17,4) | 0042 |
You can also anchor from the end with LEN: =MID(A2,LEN(A2)-3,4) returns "0042", the same as =RIGHT(A2,4). That is useful when the start depends on the length of the text.
Turn extracted pieces into a date or a number
MID always returns text. The sequence "0042" is the text "0042", with its leading zeros. Convert it when you need a number: =MID(A2,17,4)+0 returns 42, and =VALUE(MID(A2,17,4)) also returns 42. Keep the text form if the zeros matter, as they do for codes.
To turn the ship date into a real Excel date, feed three MID calls to DATE:
=DATE(MID(A2,3,4),MID(A2,7,2),MID(A2,9,2))
The year starts at 3 and takes 4, the month starts at 7 and takes 2, the day starts at 9 and takes 2. Excel returns the serial number 46329, which you format as a date to see 3 November 2026. DATE accepts the text pieces and converts them for you.
MID and FIND function in Excel
Fixed positions break the moment the length varies. Column B has contacts like "Dlamini, Sipho (Finance)" where the department sits between brackets, and the names are different lengths on every row. MID with FIND solves it. FIND locates each bracket, and the arithmetic tells MID where to start and how many characters to keep.
=MID(B2,FIND("(",B2)+1,FIND(")",B2)-FIND("(",B2)-1)
Read it in three parts:
- start_num: FIND("(",B2)+1. The opening bracket is at position 16 in B2, so the department starts at 17, one character after it.
- num_chars: FIND(")",B2)-FIND("(",B2)-1. The closing bracket is at 24. 24 minus 16 minus 1 is 7, the length of "Finance".
- MID joins them: start at 17, keep 7. The result is "Finance".
The recipe works for any pair of markers. The start is the position of the left marker plus the length of that marker, and the length is the right marker's position minus the left marker's position minus the length of the left marker. For single-character markers that is the "+1" and "-1" you see above. For a multi-character marker, such as " - ", use 3 instead.
If one of the markers is missing in a row, FIND returns #VALUE! and so does the whole formula. Wrap it in IFERROR to show a blank or a note.
Get a first name from Surname, First Name
MID also handles the middle of a "Surname, First name (Department)" layout. The surname is simple with LEFT: =LEFT(B2,FIND(",",B2)-1) returns "Dlamini". The first name sits between the comma and the space before the bracket:
=MID(B2,FIND(",",B2)+2,FIND(" (",B2)-FIND(",",B2)-2)
The comma is at position 8, so the name starts at 10, after the comma and the space. The " (" is at position 15. 15 minus 8 minus 2 is 5, the length of "Sipho". The result is "Sipho". On B4 the same formula returns "Johan", and the multi-word surname "van Wyk" does not interfere because the formula keys on the comma.
What MID does when you run past the end
MID is forgiving about length and strict about the start. These are the behaviors, tested on A2:
| Formula | Returns | Why |
| =MID(A2,18,50) | 042 | Asking for more than exists stops at the end of the text |
| =MID(A2,25,3) | empty text | The start is past the end of the 20-character text |
| =MID(A2,0,3) | #VALUE! | start_num must be at least 1 |
| =MID(A2,3,-1) | #VALUE! | num_chars cannot be negative |
MID with TEXTBEFORE, TEXTAFTER and TEXTSPLIT
Microsoft 365 and Excel 2024 added functions that cut text at a delimiter, no counting needed. For the department in B2:
=TEXTBEFORE(TEXTAFTER(B2,"("),")")
TEXTAFTER(B2,"(") returns "Finance)", everything after the bracket. TEXTBEFORE of that with ")" trims at the closing bracket and returns "Finance". Two functions, no position arithmetic.
TEXTSPLIT breaks one cell into several. =TEXTSPLIT(B2,", ") spills "Dlamini" and "Sipho (Finance)" into two neighboring cells.
These functions are easier to read, but they only exist in newer Excel. MID with FIND runs in every version, so keep it for workbooks that go to people on older builds. Also remember that MID is the right tool for fixed-width codes, where no delimiter exists. Nothing in TEXTBEFORE can cut "WB20261103JNBCPT0042" into its date, hubs and sequence.
Test or count rows with MID
MID works inside conditions. =IF(MID(A2,11,3)=MID(A2,14,3),"Same hub","Transfer") compares origin and destination, and returns "Transfer" for row 2 since JNB and CPT differ.
To count parcels leaving Johannesburg, use =SUMPRODUCT(--(MID(A2:A6,11,3)="JNB")), which returns 2. And if the position of a hub code varies, let SEARCH find it: =MID(A3,SEARCH("JNB",A3),3) returns "JNB" in row 3.
MID compared with its alternatives
| Job | Best tool | Example |
| Fixed-width slice from the middle | MID | =MID(A2,11,3) |
| First N characters | LEFT | =LEFT(A2,2) |
| Last N characters | RIGHT | =RIGHT(A2,4) |
| Text between two markers, every version | MID with FIND | =MID(B2,FIND("(",B2)+1,FIND(")",B2)-FIND("(",B2)-1) |
| Text between two markers, newer Excel | TEXTBEFORE and TEXTAFTER | =TEXTBEFORE(TEXTAFTER(B2,"("),")") |
| Split a column into many | Text to Columns or TEXTSPLIT | Data tab, Text to Columns |
| Everything except a prefix | MID with a large count | =MID(A2,11,100) |
Excel versions that have MID
Microsoft lists MID for Microsoft 365 on Windows and Mac, Excel 2024, 2021, 2019 and 2016, and it is also available in Excel for the web. MIDB, the byte-based sibling, is marked deprecated.
TEXTBEFORE, TEXTAFTER and TEXTSPLIT are on Microsoft's list for Microsoft 365 and Excel 2024 on Windows and Mac. They are not in Excel 2021 or 2019. The Microsoft pages do not list Excel for the web, so check there by typing the function name into a cell and seeing whether autocomplete offers it.
MID errors and their fixes
| What you see | Cause | Fix |
| #VALUE! with a start of 0 | start_num is less than 1 | Start at 1 or higher. Check for an off-by-one error |
| #VALUE! with a negative count | The arithmetic in num_chars went below zero, often because the markers are in the wrong order | Check which marker comes first in the text |
| #VALUE! from MID with FIND | FIND did not find the marker | Wrap in IFERROR, or clean the text so the marker exists |
| Empty result | start_num is past the end of the text | Check LEN of the text against your start |
| A number that will not add up | MID returned text | Wrap in VALUE or add 0 |
| The wrong slice | Off by one on the start | Count characters, remembering that 1 is the first |
What learners get wrong
Between 26 September and 3 November 2026, learners made 1,389 first attempts across our MID Function lesson, and 76.3% were right. The figure counts first checks of a screen in a page view, not people.
A good share of the errors come from the start position or the target cell. Three screens show it.
- Write a MID formula that returns "South" from the cell A1. 134 first attempts, 65.7% right. The accepted answer is =mid(a1,5,5). The wrong answers show three different slips. 21 first attempts used =mid(a6,1,5), which points at A6 instead of A1 and starts at position 1 instead of 5. 17 used =mid(a1,4,5), starting one character early. 3 used =mid(a1,5,9), asking for nine characters when five were needed, which drags in the text after the word.
- Write a MID formula that returns "pin" from a table. 138 first attempts, 79.0% right, with =mid(b4,2,3) accepted. 5 first attempts typed the word itself inside the formula, as in =mid("Spinach",2,3), instead of pointing at the cell. It returns the right letters but ignores the table, so it does not follow the data when the cell changes. Another 3 used =mid(b4,2,4), one character too many.
- Predict what MID returns on a word. The screen that uses "hello" drew 156 first attempts and only 48.1% were right. 7 first attempts typed =mid("hello",2,3) again, repeating the formula instead of its result. The correct answer is the three letters starting at the second position. The most common wrong answer on that screen, with 35 first attempts, began one position later than it should.
The mixed practice lesson, LEN, LEFT, RIGHT, MID Practice, logged 974 first attempts in the same window, with 85.2% right. That is well above the 76.3% of the single-function lesson.
Worked scenario: break a courier export into columns
Your operations lead wants the waybill list split into ship date, origin, destination and department, so it can feed a report.
- In C1 to F1 add the headers Ship date, Origin, Destination and Department.
- In C2 type =DATE(MID(A2,3,4),MID(A2,7,2),MID(A2,9,2)) and format the column as a date. Row 2 shows 3 November 2026.
- In D2 type =MID(A2,11,3) and in E2 type =MID(A2,14,3). Row 2 shows JNB and CPT.
- In F2 type =MID(B2,FIND("(",B2)+1,FIND(")",B2)-FIND("(",B2)-1). Row 2 shows Finance, row 5 shows HR.
- Fill all four formulas down to row 6.
- Count how many parcels left JNB with =SUMPRODUCT(--(MID(A2:A6,11,3)="JNB")), which returns 2.
- Copy the result columns and paste them as values before sharing, so the report does not depend on the raw codes.
Practice MID in the lessons
You will remember MID better by typing it than by reading about it. Open Lesson 50, MID Function, and type your answer to the first screen. Then try Lesson 62, LEN, LEFT, RIGHT, MID Practice, where the questions mix all four functions. For the full set of text tools, see the Excel text functions guide.
FAQ
What does the MID function do in Excel?
MID returns a set number of characters from the middle of text, starting at a position you choose. =MID(A2,3,8) starts at the third character of A2 and returns eight characters. It needs three arguments: the text, the start position and the number of characters to return.
How do I use MID and FIND together in Excel?
Let FIND locate the markers and feed the positions to MID. To get the text inside brackets, use =MID(B2,FIND("(",B2)+1,FIND(")",B2)-FIND("(",B2)-1). The start is one past the opening bracket, and the length is the gap between the two brackets minus one.
What happens if MID goes past the end of the text?
If the start is beyond the last character, MID returns empty text. If the start is valid but you ask for too many characters, MID returns what exists and stops at the end. Only a start below 1 or a negative length produces #VALUE!.
Why does MID return text instead of a number?
MID always returns text, even when the characters are digits. Excel will not sum or look up that text as a number. Convert it with =VALUE(MID(A2,17,4)) or add zero. Keep the text form when leading zeros matter, as in product codes.
Is there a modern replacement for MID in Excel?
For delimited text, TEXTBEFORE, TEXTAFTER and TEXTSPLIT often replace MID with FIND in Microsoft 365 and Excel 2024. For fixed-width codes with no delimiter, MID is still the right tool, and it works in every version of Excel.
How do I get everything after the first few characters?
Use MID with a large count: =MID(A2,11,100) returns everything from character 11 to the end. The count only needs to be at least as long as the remaining text. Alternatively, use =RIGHT(A2,LEN(A2)-10) to drop the first ten characters.
Sources
Keep going
Guides people read next.
SUMIF Function in Excel: Sum If Text, Numbers, Dates
Learn the Excel SUMIF formula: sum if a cell equals text, passes a number test, matches a wildcard or falls after a date, plus fixes for wrong totals.
16 minExcel FILTER Function: Extract Matching Rows
The Excel FILTER function returns only the rows that meet a condition and spills the result. Syntax, AND/OR examples, and an interactive FILTER lesson.
3 minExcel Text Functions: Complete Guide to LEFT, MID, RIGHT, LEN, TRIM, SUBSTITUTE and More
Master Excel text functions: LEFT, MID, RIGHT, LEN, TRIM, UPPER, LOWER, SUBSTITUTE, REPLACE, FIND, SEARCH, CONCAT, TEXTJOIN, and TEXT with examples.
11 min