The Excel MID function pulls a set number of characters out of the middle of a text string, starting at whatever position you choose. Its syntax is =MID(text, start_num, num_chars): text is the cell or string you read from, start_num is the position of the first character you want, and num_chars is how many characters to return. For example, =MID("AB-1234-XY",4,4) returns 1234. It works in every current desktop and mobile Excel version, including Excel for Microsoft 365, Excel 2021 and Excel for the web, and nothing needs installing. The only real prerequisite is knowing where your target text starts inside the cell, which the companion functions FIND, SEARCH or LEN usually supply.
What You'll Need
- A version of Excel that supports MID - Excel 2007 or later on Windows or Mac, Excel for the web, or the Excel mobile app. MID is a legacy text function, so it is available everywhere.
- A sheet with the text you want to split, ideally with a couple of messy real examples rather than tidy test data.
- A free empty column next to the data for your formula, so you do not overwrite the original text.
- A basic sense of which character position your target begins at. If that position moves between rows, you will use FIND or SEARCH inside MID to work it out automatically.
Step-by-Step
- Inspect the data first. Click one cell and look at the formula bar. Note exactly where the part you want sits and whether a separator such as a dash, space, comma or slash always comes before it. Write down a sample value and count the characters by hand once - this stops you guessing at positions later.
- Write the simplest possible MID formula. In an empty cell type
=MID(A2,4,4), replacingA2with your text cell. Press Enter. You should see exactly four characters starting at the fourth character. If the result is shorter than you expected, the source text ran out - see the troubleshooting section. - Count from the left, not from your visible text. MID counts spaces, punctuation and leading zeros as characters. A value like
INV 00123with a leading space has shifted everything one position to the right, so=MID(A2,6,5)might be needed instead of5. - Replace the fixed start with FIND when the position varies. If the useful text always follows a dash, calculate the position instead of hard-coding it:
=MID(A2,FIND("-",A2)+1,4). FIND returns the position of the first dash and the+1moves you past it. - Use SEARCH if the separator case changes. FIND is case-sensitive and does not accept wildcards; SEARCH ignores case, so
=SEARCH("x",A2)finds both "x" and "X". Swap it in when your data is inconsistently capitalised. - Handle the length with LEN when you want everything after the separator. If the tail length varies, pass a number larger than the remaining text:
=MID(A2,FIND("-",A2)+1,99). MID simply returns what is there and does not pad or error, so a generous count is safe for a fixed-position tail. - Work a complete example. Say A2 contains
ORD-2024-0457-USand you want the year. The first dash is at position 4, so=MID(A2,5,4)returns2024. To get the country code instead, use=MID(A2,FIND("-",A2,FIND("-",A2)+1)+1,2), which finds the second dash and returnsUS. - Fill the formula down the column. Drag the fill handle or double-click its bottom-right corner. Check three or four results against the source, especially the shortest and longest values, because those expose off-by-one errors fastest.
- Convert results to values if you are deleting the source. Select the formula column, copy it, then use Paste Special > Values (or right-click > Paste Options > Values). This replaces the formulas with plain text so they survive if the original column is removed.
- Wrap in IFERROR for untidy data. If some rows lack the separator, FIND returns a #VALUE! error and MID carries it through. Use
=IFERROR(MID(A2,FIND("-",A2)+1,4),"")to leave a blank instead.
Note that menu labels and function behaviour can differ slightly by Excel version, platform and region. On Excel for the web and the mobile apps, the same formulas work, but Paste Special is reached through a different menu than on the desktop.
Common Mistakes
- Counting from one instead of zero. Unlike many programming languages, Excel's first character is position 1, not 0. A start_num of 0 returns a #VALUE! error.
- Confusing start position with character count.
=MID(A2,4,4)means "four characters beginning at the fourth", not "characters four through four". Mixing the two arguments up produces plausible-looking but wrong output. - Forgetting that MID returns text. The result
2024is a text string, not a number. If you need to sort or calculate with it, wrap it in VALUE:=VALUE(MID(A2,5,4)). - Assuming FIND is case-insensitive. It is not, and it treats wildcard characters literally. Use SEARCH when you need loose matching.
- Deleting the source column before converting formulas to values. Moving or deleting the referenced cells leaves
#REF!errors everywhere. - Ignoring trailing and leading spaces. Clean data with
=TRIM(A2)first, or trim inside the formula, if positions keep shifting by one or two characters.
Tips
- Use
=MID(A2,1,n)as a quick left-side grab; it is equivalent to LEFT but useful when the start point is a cell reference you reuse. - Nest MID inside other functions -
=TEXT(MID(A2,5,6),"0000-00")can format a date string pulled from an ID. - Test on the shortest possible value in your column, not the longest. Short strings reveal "ran out of characters" bugs that long strings hide.
- Put your separator and position values in helper cells (for example, the dash character and the wanted length) so you can adjust the whole column by editing one cell.
- Use Text to Columns or Power Query when you are splitting many fields with consistent separators - it is faster than stacking several MID formulas.
- Remember MID counts each character including spaces; for text containing line breaks, wrap the source in CLEAN or TRIM first.
Troubleshooting
- #VALUE! error. The most common cause is start_num less than 1, a non-numeric argument, or FIND not finding the separator. Check the separator exists in that exact cell.
- Result is shorter than num_chars. That is normal behaviour: MID stops at the end of the string and returns what remains. It never pads with spaces.
- Wrong characters returned. Recount positions in the formula bar, not the displayed cell, and check for leading spaces. TRIM the source first.
- Formula works in one row, fails below. A hard-coded start position usually means the data layout varies between rows. Switch to FIND or SEARCH so the position is computed.
- Copied results show errors. The relative references shifted. Lock the source with
$signs (for example$A2) or confirm they point at the right column. - Nothing changes when you edit the source. Check calculation is set to Automatic, or press F9 to recalculate.
- Output is text but you need numbers. Wrap the result in VALUE, or multiply by 1, then reformat the cell.
Frequently Asked Questions
What is the difference between MID, LEFT and RIGHT?
LEFT returns characters from the very start, RIGHT from the very end, and MID from any position you specify. MID is the general tool; LEFT and RIGHT are conveniences for the two edges.
Does MID work with numbers?
Yes, but the result is always text. If you need to sort or calculate with it, convert it with VALUE.
Can MID extract text between two delimiters?
Yes. Combine FIND with LEN: =MID(A2,FIND("[",A2)+1,FIND("]",A2)-FIND("[",A2)-1) pulls everything between brackets. The same pattern works with any pair of separators.
Why does MID return fewer characters than I asked for?
Because the string ended first. MID returns whatever remains and never pads or errors in that case.
Is MID case-sensitive?
MID itself is not - it simply copies characters. The case sensitivity question applies to FIND, which is case-sensitive, versus SEARCH, which is not.
Can I use MID on a whole column at once?
Yes, in Microsoft 365 you can enter the formula once and let it spill, or fill it down with the fill handle. In older versions, fill down manually.