Excel MID Function: Extract Text from the Middle of a Cell

Formulas & functions · Updated November 18, 2026

Excel’s MID function extracts a chosen number of characters from the middle of a text string. Its syntax is =MID(text, start_num, num_chars): give it the text, the position to begin at, and how many characters to return.

What the MID Function Does

MID is useful when the characters you need sit between the beginning and end of a cell’s contents. Unlike LEFT and RIGHT, it lets you specify where extraction starts. The function returns text, even if the extracted characters look like a number. That makes it handy for pulling out product codes, initials, date components, reference numbers, or sections of a longer label.

For example, a fixed-format inventory code might contain a three-character category followed by a hyphen and then a four-digit item number. If the code is stored in one cell, MID can return just the item number. It does not change the original cell; it produces a separate result wherever you enter the formula.

MID counts characters from left to right, starting at position 1—not position 0. Spaces and punctuation count as characters too. So in a string such as ABC-123, the hyphen occupies a position and affects the position number of everything after it.

MID Syntax and Its Three Arguments

The three arguments have distinct jobs. text is the source string or cell reference; start_num is the position of the first character to return; and num_chars is the number of characters to return. The last two arguments are numbers, and the start position must be at least 1.

  • text: The string to search within, often a cell such as A2.
  • start_num: The character position where extraction begins. The first character is position 1.
  • num_chars: The maximum number of characters to return.

Excel truncates decimal values supplied for the position and character-count arguments to integers. In ordinary worksheets, use whole numbers to make the intended extraction clear. If the requested character count extends beyond the end of the text, MID returns the available characters rather than an error. If the start position is beyond the end, it returns an empty string.

Basic MID Examples

Suppose A2 contains the text INV-5832. With that value in A2, this formula starts at character 5 and returns four characters, producing 5832:

With the code INV-5832 in A2, enter =MID(A2,5,4) in B2. The result is 5832, returned as text.

For a shorter extraction, suppose A2 contains ABC-12345. This formula starts at position 1 and returns three characters, so the result is ABC:

With ABC-12345 in A2, enter =MID(A2,1,3) in B2. The result is ABC.

When the source is a fixed-width string, the position and count can be entered directly. For example, a text value containing a date in YYYYMMDD format has the month in positions 5 and 6. With the date text 20261102 in A2, enter =MID(A2,5,2) in B2. The result is 11. Because MID returns text, Excel does not automatically turn that result into a numeric month value.

To reuse a formula down a column, enter it beside the first source value and fill or copy it down. A relative reference such as A2 changes to A3 in the next row, so each result uses the corresponding source cell. If you need a fixed source cell in a more complex formula, an absolute reference such as $A$2 keeps it from shifting when copied.

Extracting Text When the Position Can Change

A fixed start position works only when every source string follows the same layout. If the number of characters before the target varies, combine MID with a function that locates a delimiter. FIND returns the position of specified text and is case-sensitive. Adding 1 to the position of a hyphen starts extraction just after that hyphen.

With Order-7391-Blue in A2, enter =MID(A2,FIND("-",A2)+1,4) in B2. FIND locates the first hyphen, and MID returns the next four characters, giving 7391.

When the target’s length also varies, calculate the character count from the positions of two delimiters. With ID:Q7M4|status in A2, enter =MID(A2,FIND(":",A2)+1,FIND("|",A2)-FIND(":",A2)-1) in B2. The colon is at position 3 and the vertical bar at position 8, so the count is 8 − 3 − 1 = 4. MID returns Q7M4.

These formulas assume the expected delimiters exist. If FIND cannot locate a delimiter, it returns an error, which makes the larger formula return an error too. If a missing delimiter should produce a blank instead, use IFERROR. With source strings in A2, enter =IFERROR(MID(A2,FIND("-",A2)+1,4),"") in B2. It returns four characters after the first hyphen when available, and a blank if the formula encounters an error. Use this deliberately: IFERROR also hides errors other than a missing hyphen.

Choosing Between MID, LEFT, RIGHT, and Other Functions

Use the extraction function that matches the structure of the text. LEFT returns characters from the beginning, RIGHT returns characters from the end, and MID starts at a position you specify. If your text is separated by a delimiter rather than stored at fixed character positions, a delimiter-based function may be easier to maintain.

  • Use LEFT for a prefix, such as the first three characters of a code.
  • Use RIGHT for a suffix, such as the last four characters of an identifier.
  • Use MID for characters at a known position or between positions you calculate.
  • Consider TEXTBEFORE or TEXTAFTER when the goal is to return text on one side of a delimiter. These functions are available in Microsoft 365 and Excel 2024.

For example, if a code has variable-length text before a hyphen, MID with FIND can extract a fixed number of characters after it. TEXTAFTER may express that delimiter-based task more directly when you want everything after the delimiter. The best choice depends on whether you need a fixed number of characters, a fixed position, or all the text before or after a separator.

Excel for Microsoft 365 on Windows uses the same MID function and syntax as Excel for Mac and Excel for the web. In some regional settings, Excel expects semicolons rather than commas between formula arguments; follow the separator used by your installation if a comma-separated formula is rejected. Function availability and the extraction logic are otherwise the same.

Common MID Errors and How to Fix Them

A few input mistakes account for most problems with MID. Check the starting position and character count first, then verify that any delimiter-searching function can find the characters it is looking for.

  • #VALUE!: A start position below 1 or a negative character count causes this error. Confirm that the arguments are valid nonnegative counts and that the start position is at least 1.
  • Blank result: The start position may be past the end of the source string, or the requested character count may be zero. Check the actual positions, including spaces and punctuation.
  • #VALUE! in a delimiter formula: FIND may not find the delimiter, or the formula may search for the wrong character. Confirm the source text and delimiter spelling.
  • Unexpected character: A separator, leading space, or other character may have been overlooked when counting. Inspect the source string one character at a time.
  • Digits that do not behave like numbers: MID returns text. If you need arithmetic, convert the extracted digits to a number where appropriate, and check that the source contains only numeric characters.

One common misconception is that the count refers to the ending position. It does not: num_chars is the number of characters to return, starting at start_num. For instance, starting at position 4 and requesting 3 characters returns positions 4, 5, and 6—not everything through position 3.

Character Counting and MIDB

MID counts characters, not the number of bytes used to store text. The related MIDB function counts bytes in languages that use double-byte character sets. For most current Excel work, MID is the appropriate choice; MIDB is mainly relevant when maintaining older workbooks built around byte-based extraction behavior.

Text containing accented letters, symbols, or characters from different writing systems can make character handling less obvious. If a formula produces an unexpected result in multilingual data, check the actual characters and test the extraction on a few representative strings. Do not assume that a character’s visual width or its storage size determines its position in MID. For normal text extraction, count the characters as Excel interprets them.

Leading and trailing spaces are also part of the text. MID does not clean them up automatically. If spaces interfere with the positions, decide whether they are meaningful before removing them; trimming can change character positions and therefore change the result of a position-based formula.

Frequently Asked Questions

What is the Excel formula for text in the middle?
Use =MID(text, start_num, num_chars). Replace the arguments with the source cell or text, the position to start at, and the number of characters to return.

Does MID start counting at 0 or 1?
It starts at 1. The first character in the source text is position 1, and spaces and punctuation each count as characters.

Can MID extract text between two characters?
Yes. Combine MID with FIND to locate the starting and ending delimiters, then calculate how many characters lie between them. The formula needs to account for the delimiter positions and assumes those delimiters are present.

Why does MID return a blank?
A start position beyond the end of the string returns an empty result. A zero character count also requests no characters. Check the source length and the formula’s position and count.

Does MID return a number or text?
MID returns text. A result made up of digits may look numeric, but Excel may treat it as text in calculations. Convert it to a number if the next step requires numeric arithmetic.

Is MID the same in Excel for Mac and the web?
Yes. The function name and argument order are the same in current Excel for Windows, Mac, and the web. Depending on regional settings, the argument separator shown in a formula may differ.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.