ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. MID Function in Excel: Pull Text From the Middle

MID Function in Excel: Pull Text From the Middle

By ExcelReady Team·Updated November 1, 2026·7 min read

The short answer

The MID function in Excel returns a set number of characters from the middle of text. Write =MID(text, start_num, num_chars): the text, the position to start at, and how many characters to take. For example, =MID("ORD-2024-0081",5,4) returns 2024. For text of varying length, use FIND or SEARCH to work out the start position.

Key takeaways

  • The shape is =MID(text, start_num, num_chars); the first character is position 1.
  • MID(A2,5,4) starts at character 5 and returns 4 characters.
  • If num_chars runs past the end, MID just returns what is left, with no error.
  • Use FIND or SEARCH to find a start position when the text varies in length.
  • MID always returns text, so wrap it in VALUE for a number you can add up.
On this page+
  1. What does the MID function do?
  2. How to use MID with a fixed position
  3. What happens if num_chars is too big?
  4. How to use MID with FIND for variable lengths
  5. How to extract text between two characters
  6. Why does MID return a number I can't add up?
  7. Common mistakes with MID
  8. Practise it

The MID function in Excel pulls characters out of the middle of a cell. You tell it where to start and how many characters to take, so =MID("ORD-2024-0081",5,4) returns 2024. This guide is for anyone cleaning codes, IDs or imported text, and it covers fixed positions, variable positions with FIND, and the errors to watch for.

What does the MID function do?#

MID returns part of a text string, starting at any position you choose. The syntax has three parts:

Excel formula
=MID(text, start_num, num_chars)
PartWhat it meansExample
textThe text or cell to read fromA2
start_numThe position of the first character you want5
num_charsHow many characters to return4

Positions start at 1, not 0. Spaces, dashes and punctuation all count as characters. MID works in every version of Excel, on Windows and Mac.

MID's siblings are LEFT, which takes characters from the start, and RIGHT, which takes them from the end. The overview of LEFT, RIGHT and MID compares all three. MID is the one you need when the part you want sits between other parts.

How to use MID with a fixed position#

When every value has the same layout, count the positions once and use fixed numbers. Take order IDs like ORD-2024-0081:

Position12345678910111213
CharacterORD-2024-0081

The year starts at position 5 and is 4 characters long:

Excel formula
=MID(A2,5,4)

The result is 2024. The order number starts at position 10 and is also 4 long, so =MID(A2,10,4) returns 0081.

If you're not sure how long a value is, LEN counts the characters for you: =LEN(A2) returns 13 here. The guide to counting characters with LEN shows more ways to use it.

What happens if num_chars is too big?#

Nothing breaks: MID returns whatever is left and stops at the end of the text. This makes a handy shortcut for "everything from position N onwards":

Excel formula
=MID(A2,10,100)

This returns 0081, because only 4 characters remain after position 10. Using a large number like 100, or LEN(A2), means you don't need to calculate the exact length.

Two more edge cases are worth knowing:

FormulaResultWhy
=MID(A2,20,4)(empty text)Start is past the end of the text
=MID(A2,0,4)#VALUE!Start must be 1 or more
=MID(A2,5,-1)#VALUE!Length can't be negative

How to use MID with FIND for variable lengths#

When the part you want moves around, let FIND work out the start position. FIND returns the position of one piece of text inside another. Say product codes have a region of any length, a dash, then a three-letter category: TX-ELC-40512 or CALIF-HOM-118.

To get the category, start one character after the first dash:

Excel formula
=MID(A2,FIND("-",A2)+1,3)
A2FIND("-",A2)StartResult
TX-ELC-4051234ELC
CALIF-HOM-11867HOM

The +1 matters. Without it, MID starts on the dash itself and returns -EL.

FIND is case-sensitive. SEARCH works the same way but ignores case and allows wildcards. For finding a single character like a dash or @, either one is fine.

How to extract text between two characters#

To get text between two markers, use FIND twice: once for the start, once to work out the length. Say A2 holds Smith, John (Sales) and you want the department inside the brackets:

Excel formula
=MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1)
PieceValueMeaning
FIND("(",A2)13Position of the opening bracket
FIND(")",A2)19Position of the closing bracket
Start14One after the opening bracket
Length19 − 13 − 1 = 5Characters between the brackets

The result is Sales. This pattern looks long, but it's always the same shape: start after the first marker, length is the gap between the markers minus one. There's a full walkthrough in extracting text between two characters, and the same idea pulls out a domain name in extracting the domain from an email address.

In Microsoft 365 or Excel 2024, TEXTAFTER and TEXTBEFORE can do this with less typing: =TEXTBEFORE(TEXTAFTER(A2,"("),")"). MID with FIND still works in every version, which matters in job tests that use older Excel.

Why does MID return a number I can't add up?#

MID always returns text, even when the result looks like a number. The year 2024 from the order ID is text: it sits on the left of the cell, and SUM ignores it.

To get a real number, wrap MID in VALUE:

Excel formula
=VALUE(MID(A2,5,4))

Now the result is the number 2024, which you can compare, sort and calculate with. A quick alternative is =MID(A2,5,4)+0, but VALUE is clearer for anyone reading your formula later.

Common mistakes with MID#

Most MID mistakes come from counting positions wrong. Check these:

  1. Starting at 0. The first character is position 1. MID(A2,0,4) returns #VALUE!.
  2. Forgetting the +1 after FIND. Without it, the result includes the marker character.
  3. FIND can't find the marker. If a row has no dash, FIND returns #VALUE! and so does MID. Wrap it in IFERROR to show a blank or a message.
  4. Hidden spaces. A leading space shifts every position by one. Clean the column with TRIM first.
  5. Expecting a number. MID returns text. Use VALUE before maths or number lookups.

Practise it#

MID shows up in data-cleaning questions in many Excel job tests, often combined with FIND. Practise LEFT, RIGHT, MID and LEN in a live spreadsheet: you type the formula, and it checks your answer instantly. The MID function guide is a quick syntax reference, and the guide to splitting a full name into first and last puts these functions to work on real data.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Order IDs follow the pattern ORD-2024-0081. Click B2 and use MID to pull out the 4-digit year, which starts at character 5.

fx
ABCD
1
Order ID
Year
2
ORD-2024-0081
3
ORD-2023-1145
4
ORD-2025-0007
5
ORD-2024-0932
6
ORD-2025-0410
7
8
9

Tip: Count the characters: O, R, D and the dash take positions 1 to 4, so the year starts at 5 and is 4 characters long.

Practise this in a lesson

LessonLEFT, RIGHT, MID and LENSplit product codes and IDs into their parts by taking characters from the start, end or middle of the text.Function guideMIDPull characters from any position with Excel's MID. Extract IDs, email domains and text between brackets with FIND. Examples and live practice.

Frequently asked questions

What does the MID function do in Excel?

+

MID returns characters from the middle of a text string. You give it the text, the position to start at and how many characters to return, as in =MID(A2,5,4).

How do I use MID with a variable length?

+

Use FIND or SEARCH to calculate the start position or the number of characters. For example, =MID(A2,FIND("-",A2)+1,3) returns the three characters after the first dash, wherever it is.

Why does MID return #VALUE!?

+

The start position is less than 1, or the number of characters is negative. This often happens when FIND can't find its character, or when a calculated length goes below zero.

How do I convert the result of MID to a number?

+

MID always returns text. Wrap it in VALUE, as in =VALUE(MID(A2,5,4)), or add zero with =MID(A2,5,4)+0, to get a real number.

What is the difference between MID and MIDB?

+

MID counts every character as one. MIDB counts bytes, which only differs for some double-byte languages such as Japanese, Chinese and Korean. For most work, use MID.

Sources

  • MID, MIDB functions - Microsoft Support
  • FIND, FINDB functions - Microsoft Support
  • SEARCH, SEARCHB functions - Microsoft Support

Written and checked by the ExcelReady Team. First published November 1, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What does the MID function do?
  2. How to use MID with a fixed position
  3. What happens if num_chars is too big?
  4. How to use MID with FIND for variable lengths
  5. How to extract text between two characters
  6. Why does MID return a number I can't add up?
  7. Common mistakes with MID
  8. Practise it

Keep reading

Text· 6 min read

LEFT, RIGHT and MID in Excel: Pull Out Part of a Cell

LEFT, RIGHT and MID pull part of the text out of a cell. LEFT(text, num_chars) takes characters from the start, RIGHT(text, num_chars) takes them from the end, and MID(text, start_num, num_chars) takes them from any position. For TX-ELC-40512, LEFT(A2,2) gives TX, MID(A2,4,3) gives ELC and RIGHT(A2,5) gives 40512.

Text· 7 min read

Extract the Domain or Username From an Email in Excel

To extract the domain from an email address, take everything after the @ sign. In Microsoft 365, use =TEXTAFTER(A2,"@"). In any version, use =MID(A2,FIND("@",A2)+1,LEN(A2)). For the username, take everything before the @: =TEXTBEFORE(A2,"@") or =LEFT(A2,FIND("@",A2)-1). Wrap either in IFERROR for cells without an @.

Text· 7 min read

Count Characters and Words in a Cell in Excel

To count characters in a cell, use =LEN(A2). It counts every letter, digit, space and symbol. To count one character, subtract the length without it: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")). To count words, count the spaces in the trimmed text and add 1: =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free