How to Mid Function in Excel
Learn multiple Excel methods to mid function with step-by-step examples and practical applications.
How to Mid Function in Excel
Why This Task Matters in Excel
Extracting a specific portion of a text string—neither strictly at the beginning nor at the end—is one of the most common data-cleaning and data-analysis challenges professionals face. Whether you are standardizing product codes, splitting combined first-and-last-name fields, or isolating a critical identifier buried in a long alphanumeric key, being able to pull out the “middle” part of a string quickly and reliably turns messy data into structured, analysis-ready information.
Picture a customer-service manager who receives daily CSV exports from a ticketing platform. Each record contains a ticket ID such as “TK-2023-09-57423”. Reporting requires only the five-digit serial number at the end; the “TK-” prefix and the date stamp must be removed. Or consider an inventory specialist who scans bar-code dumps where the supplier code, item code, and color code are jammed together—“SUP438-ITEM792-BLU”. Consistent mid-segment extraction is the difference between spending hours of manual editing and having clean lookup keys in seconds.
MID and its modern cousins (TEXTBETWEEN, TEXTSPLIT, and dynamic array formulas) give Excel users surgical control over text. Because Excel stores everything from account numbers to addresses in cells, mastering mid-string extraction underpins broader skills: creating dashboards, automating reports with Power Query, validating data entered by colleagues, and integrating with external systems that enforce strict data formats. Not knowing how to isolate the required substring can lead to duplicate records, mismatched VLOOKUP or XLOOKUP results, and downstream errors that cost time and damage confidence in reports. In short, the ability to “mid function” is a foundational competency that supports database joins, KPI calculations, and any workflow that depends on clean, well-structured text data.
Best Excel Approach
For most versions of Excel, the classic MID function remains the fastest, most portable, and easiest-to-audit approach. Its three-argument syntax is straightforward:
=MID(text, start_num, num_chars)
- text – the original string (a cell reference such as A2 or a quoted literal).
- start_num – the character position where extraction should begin; the first character in the string is position 1.
- num_chars – how many characters to return from that point.
Why MID is “best” in many situations:
- Compatibility – Works in every desktop version back to Excel 2003 and in all web versions.
- Predictability – Always returns fixed-width output, making it easy to feed into other formulas or pivot tables.
- Transparency – Any analyst can open the file and immediately understand what MID is doing because the logic is explicit.
When might you choose something else? If you need the characters between two markers of unknown position, TEXTBETWEEN in Microsoft 365 can be more intuitive. If you need to split a delimited string into multiple columns automatically, TEXTSPLIT or the legacy Text-to-Columns wizard may be better. However, the underlying logic—find the start, count the length—remains the same, so thinking in terms of MID helps you reason about all extraction tasks.
Parameters and Inputs
To use MID effectively, you must supply clean inputs:
- text (required) – Must be a text value. Numbers formatted as text work, but true numeric values must be coerced using the TEXT function or concatenation (\"\"&A2).
- start_num (required) – Positive integer greater than or equal to 1. Zero or negative numbers trigger a #VALUE! error.
- num_chars (required) – Non-negative integer. If it exceeds the remaining length of the string, Excel simply returns everything until the end—no error.
- Optional dynamic ranges – In Office 365 you can supply entire arrays (e.g., A2:A100) as the text argument, and MID will spill results down automatically, reducing the need for copy-down.
- Hidden characters – Watch out for unprintable characters (carriage returns, non-breaking spaces). CLEAN or TRIM may be required before extraction.
- Multibyte characters – For languages such as Japanese, use MIDB (which counts bytes) if your system’s code page requires it.
Edge cases: empty text returns empty text; non-numeric start_num or num_chars returns #VALUE!. Plan validation checks—use the ISNUMBER function or data-validation rules to enforce integer inputs.
Step-by-Step Examples
Example 1: Basic Scenario – Extracting Order Numbers
Imagine a simple list in column A:
| A |
|---|
| ORD-987654 |
| ORD-123456 |
| ORD-555777 |
The task: remove the “ORD-” prefix and keep the six-digit number.
- In B2 enter:
=MID(A2,5,6)
- Copy or fill down for all rows.
Explanation: The prefix “ORD-” is four characters long, so the number starts at position 5. We want the next six characters, hence 6 for num_chars. The result in B2 is 987654. Because the string always follows the same pattern, a static start position works.
Common variations:
- Variable-length order numbers (some five digits, some six) need a different approach—combine MID with LEN (length) to capture everything after the prefix:
=MID(A2,5,LEN(A2)-4)
Troubleshooting: If blank cells appear, check for leading spaces. Apply TRIM(A2) before MID or nest TRIM inside:
=MID(TRIM(A2),5,LEN(TRIM(A2))-4)
Example 2: Real-World Application – Parsing SKU Codes in an Inventory File
Scenario: A retailer imports weekly supplier feeds where column A contains SKU codes such as “SUP438-ITEM792-BLU”. They need three separate columns: Supplier, Item, and Color.
Step 1 – Split on the first delimiter to find Supplier code.
=LEFT(A2,SEARCH("-",A2)-1)
Step 2 – Extract the Item code (middle segment). We do not know exactly where ITEM starts because supplier codes vary in length. Approach:
- Find the position of the first “-”
- Find the position of the second “-”
- Use MID with computed positions
Helper cells (for clarity):
=SEARCH("-",A2) ' returns pos of first dash
=SEARCH("-",A2,SEARCH("-",A2)+1) ' returns pos of second dash
Put it all in one formula for production:
=MID(A2,
SEARCH("-",A2)+1,
SEARCH("-",A2,SEARCH("-",A2)+1) - SEARCH("-",A2) -1)
Explanation:
- Start position = first dash + 1.
- Number of characters = position of second dash minus position of first dash minus 1.
Color (rightmost segment) can be extracted with RIGHT:
=RIGHT(A2,LEN(A2)-SEARCH("-",A2,SEARCH("-",A2)+1))
Business impact: The company can now build a pivot table summarizing sales by Supplier or Color without manual edits. With hundreds of thousands of SKUs, automating extraction avoids costly errors and accelerates replenishment decisions.
Performance considerations: Volatile functions such as INDIRECT are avoided; SEARCH and MID are fast even on large ranges. If millions of rows reside in Power Query, replicate the logic with M functions there to save memory in Excel.
Example 3: Advanced Technique – Dynamic Array Extraction with TEXTBETWEEN (Excel 365)
Suppose you receive product descriptions like “Widget [Size:XL] (Code:WX900) [Shelf:B4]”. You want to pull everything inside the square brackets for a report. While classic MID can solve this, TEXTBETWEEN simplifies it:
=TEXTBETWEEN(A2,"[","]")
But what if multiple bracketed segments exist? TEXTBETWEEN allows an instance number; we’ll extract the second instance (the parentheses block) by changing delimiters:
=TEXTBETWEEN(A2,"(",")")
Yet some colleagues still use Excel 2013. To remain compatible:
=MID(A2,
SEARCH("[",A2)+1,
SEARCH("]",A2)-SEARCH("[",A2)-1)
Then spill this across many rows with:
=MAP(A2:A200,LAMBDA(x,MID(x,SEARCH("[",x)+1,SEARCH("]",x)-SEARCH("[",x)-1)))
(Requires Office 365). That single formula creates a dynamic, auto-expanding list—no Ctrl-D fill required.
Edge case handling: If the delimiters are missing, TEXTBETWEEN can return #N/A. Supply the optional if_not_found argument:
=TEXTBETWEEN(A2,"[","]","No tag")
With MID you’d use IFERROR:
=IFERROR(MID(A2,SEARCH("[",A2)+1,SEARCH("]",A2)-SEARCH("[",A2)-1),"No tag")
Professional tip: Document custom delimiters in data-loading procedures so upstream teams maintain consistency. Inconsistent delimiters are the most common cause of extraction failures.
Tips and Best Practices
- Combine MID with SEARCH or FIND when delimiter positions vary; never hard-code the start position unless the format is guaranteed.
- Pre-trim data with TRIM and CLEAN to remove invisible characters that shift positions.
- Convert numeric-looking SKU fragments to proper numbers with VALUE after extraction if arithmetic analysis is required.
- Use dynamic named ranges or Excel Tables so formulas automatically adjust to new rows, reducing maintenance.
- For large datasets, push extraction logic into Power Query or Power BI where transformations are performed once during refresh, minimizing worksheet recalculation overhead.
- Document the logic beside the formula (e.g., cell comment or adjacent note) for future maintainers—especially important when nesting multiple SEARCH functions.
Common Mistakes to Avoid
- Wrong start index: Forgetting that Excel indexes from 1, not 0, shifts output by one character. Verify by extracting a single known character first.
- Miscounting num_chars: Hard-coding length in dynamic data yields truncated or overrun strings. Instead, calculate length with LEN or by subtracting delimiter positions.
- Ignoring hidden spaces: “ABC” and “ ABC” look identical on screen but not to Excel. Always TRIM before MID when data comes from external sources.
- Overlooking errors: SEARCH returns #VALUE! if the delimiter is missing, causing the entire MID formula to error. Wrap with IFERROR or IF(ISNUMBER(SEARCH())).
- Copying formulas as values too early: Analysts sometimes paste extraction results as static values before refreshing data, breaking automation. Preserve live formulas or use Power Query to avoid this trap.
Alternative Methods
| Method | Pros | Cons | Best for | Version Support |
|---|---|---|---|---|
| MID + SEARCH/FIND | Universal, transparent, fast | Multiple nested functions can look intimidating | Any fixed or delimiter-based pattern | All versions |
| TEXTBETWEEN | Minimal syntax, optional ignore-case, built-in error argument | Only in Microsoft 365, not available to legacy users | Extracting text between two markers | 365 only |
| TEXTSPLIT | Splits entire string into array columns, handles multi-char delimiters | Requires spill-aware workbook, still 365 only | Parsing full records into table columns | 365 only |
| Flash Fill | No formulas, very intuitive | Manual trigger, not dynamic, pattern recognition can fail | One-off cleanups, quick prototypes | 2013+ |
| Power Query | GUI-driven, no Excel formula limits, handles millions of rows | Requires refresh, learning curve | ETL processes, scheduled data loads | 2010+ with add-in, built-in 2016+ |
When to switch:
- Choose MID for speed and compatibility.
- Choose TEXTBETWEEN for readability if every stakeholder is on 365.
- Flash Fill is fine for a five-minute ad-hoc task.
- Power Query is ideal when extraction is part of a broader data-pipeline refresh.
FAQ
When should I use this approach?
Use MID (or a modern equivalent) whenever you need a repeatable, formula-driven way to isolate a substring that starts somewhere after the first character and ends before the last character. Common scenarios include stripping prefixes or suffixes, parsing IDs, and preparing lookup keys.
Can this work across multiple sheets?
Yes. Reference the text argument on another sheet, e.g.,
=MID('Raw Data'!A2,5,6)
Dynamic array versions (TEXTSPLIT, TEXTBETWEEN) also spill correctly across sheets, though you must enter them from the destination sheet.
What are the limitations?
MID cannot locate delimiters by itself—you must supply start position and length. It also does not support negative indexing and cannot evaluate regular expressions. Very large texts (more than 32,767 characters) exceed Excel’s cell limit.
How do I handle errors?
Wrap your MID logic in IFERROR:
=IFERROR(MID(A2,5,6),"Missing prefix")
Alternatively, check the presence of delimiters first:
=IF(ISNUMBER(SEARCH("-",A2)),MID(...),"No dash found")
Does this work in older Excel versions?
Yes. MID syntax has not changed for two decades. Dynamic arrays, TEXTBETWEEN, and TEXTSPLIT will not work in older versions, so fall back to MID + SEARCH for cross-version files.
What about performance with large datasets?
MID is lightweight, but when nested with multiple SEARCH calls on hundreds of thousands of rows, recalculation can slow. Consider:
- Converting dataset to Excel Table so only the used range recalculates.
- Disabling automatic calculation during large paste operations.
- Offloading transformations to Power Query or Power BI for datasets over one million rows.
Conclusion
Mastering mid-string extraction turns messy, multi-component text into structured data you can pivot, chart, and analyze with confidence. By learning both the traditional MID function and modern dynamic alternatives, you future-proof your workbooks, speed up data cleaning, and deepen your overall Excel fluency. Practice on real datasets, document your logic, and explore related text functions such as LEFT, RIGHT, SEARCH, and TEXTSPLIT to build a well-rounded toolkit. Clean data unlocks accurate insights—take the time to automate your extractions today and watch your reporting workflows transform.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.