How to Use MID in Excel

The MID function extracts a substring from the middle of a text string. Unlike LEFT and RIGHT which grab characters from the edges, MID gives you surgical precision to pull characters from anywhere...

Key Insights

  • MID extracts a specific number of characters from any position in a text string using 1-based indexing, making it essential for parsing structured data like product codes, phone numbers, and transaction IDs
  • Combining MID with FIND or SEARCH creates dynamic formulas that extract text between delimiters without hardcoding positions, adapting automatically to varying data formats
  • The most common MID errors stem from start positions that exceed string length or confusing Excel’s 1-based indexing with zero-based indexing from programming languages

Introduction to the MID Function

The MID function extracts a substring from the middle of a text string. Unlike LEFT and RIGHT which grab characters from the edges, MID gives you surgical precision to pull characters from anywhere within your text.

The syntax is straightforward:

=MID(text, start_num, num_chars)

You’ll use MID constantly when working with imported data that crams multiple values into single cells, parsing API responses, extracting product codes, or cleaning messy datasets where information is buried in the middle of text strings.

Here’s a basic example:

=MID("Product-ABC123-2024", 9, 6)

This returns ABC123 by starting at position 9 and extracting 6 characters. Notice Excel uses 1-based indexing—the first character is position 1, not 0 like most programming languages.

Understanding the Three Arguments

Let’s break down each parameter because getting these right eliminates 90% of MID-related errors.

text: The source string you’re extracting from. This can be a cell reference, a formula that returns text, or a literal string in quotes.

start_num: The position where extraction begins. Position 1 is the first character. If you specify a position beyond the string length, you get an empty string—not an error.

num_chars: How many characters to extract starting from start_num. If this exceeds the remaining characters, Excel simply returns everything from start_num to the end.

Here’s how changing each parameter affects output:

// Source text in A1: "INVOICE-2024-03-15"

=MID(A1, 9, 4)     // Returns: "2024" (starting at position 9)
=MID(A1, 14, 2)    // Returns: "03" (starting at position 14)
=MID(A1, 1, 7)     // Returns: "INVOICE" (starting at position 1)
=MID(A1, 9, 100)   // Returns: "2024-03-15" (exceeds length, returns remainder)

The flexibility of num_chars is useful—you can specify a large number to grab “everything from position X onward” without calculating exact lengths.

Practical Applications

Real-world data rarely arrives clean. Here’s where MID proves invaluable.

Extracting Area Codes from Phone Numbers:

// A1 contains: "(415) 555-0123"
=MID(A1, 2, 3)     // Returns: "415"

Parsing Product SKUs:

// A1 contains: "CAT-Electronics-2024-LG-001"
// Extract department code (positions 5-16)
=MID(A1, 5, 12)    // Returns: "Electronics"

// Extract year
=MID(A1, 18, 4)    // Returns: "2024"

// Extract size code
=MID(A1, 23, 2)    // Returns: "LG"

Isolating Middle Initials:

// A1 contains: "John Q. Public"
=MID(A1, 6, 1)     // Returns: "Q"

Extracting Transaction IDs from Log Entries:

// A1 contains: "2024-03-15 14:23:01 TXN:A7B9C2 Status:Complete"
=MID(A1, 25, 6)    // Returns: "A7B9C2"

The challenge with these examples? They assume fixed positions. Real data varies, which is why combining MID with other functions is critical.

Combining MID with Other Functions

Static positions break when data formats vary. Dynamic formulas adapt automatically.

Using MID with FIND to Extract Text Between Delimiters:

// A1 contains: "Order [ORD-12345] shipped on 2024-03-15"
// Extract order number between brackets

=MID(A1, FIND("[", A1) + 1, FIND("]", A1) - FIND("[", A1) - 1)
// Returns: "ORD-12345"

Breaking this down:

  • FIND("[", A1) locates the opening bracket
  • + 1 moves to the character after the bracket
  • FIND("]", A1) - FIND("[", A1) - 1 calculates characters between brackets

Extracting Email Domains:

// A1 contains: "user@company.com"
=MID(A1, FIND("@", A1) + 1, LEN(A1))
// Returns: "company.com"

Extracting Values Between Delimiters with Multiple Occurrences:

// A1 contains: "Name:John|Age:32|City:Boston"
// Extract age value

=MID(A1, FIND("Age:", A1) + 4, FIND("|", A1, FIND("Age:", A1)) - FIND("Age:", A1) - 4)
// Returns: "32"

Converting Extracted Text to Numbers:

// A1 contains: "QTY:0025 PRICE:1499"
=VALUE(MID(A1, 5, 4))      // Returns: 25 (as number)
=VALUE(MID(A1, 16, 4))     // Returns: 1499 (as number)

The VALUE function strips leading zeros and converts text to numbers for calculations.

Trimming Extracted Results:

// A1 contains: "Code: ABC123  "
=TRIM(MID(A1, 7, 10))      // Returns: "ABC123" (removes extra spaces)

Common Errors and Troubleshooting

#VALUE! Error - Invalid Start Position:

// A1 contains: "Test"
=MID(A1, 0, 2)     // ERROR: start_num must be >= 1
=MID(A1, -1, 2)    // ERROR: start_num cannot be negative

// Correct version:
=MID(A1, 1, 2)     // Returns: "Te"

Empty Results When Start Position Exceeds Length:

// A1 contains: "Short" (5 characters)
=MID(A1, 10, 3)    // Returns: "" (empty string, not error)

// Fix with error handling:
=IF(LEN(A1) >= 10, MID(A1, 10, 3), "N/A")

Off-by-One Errors:

// A1 contains: "ABCDEFG"
// Want to extract "CDE" (positions 3-5)

=MID(A1, 3, 3)     // CORRECT: Returns "CDE"
=MID(A1, 2, 3)     // WRONG: Returns "BCD" (started too early)
=MID(A1, 3, 4)     // WRONG: Returns "CDEF" (extracted too many)

Remember: Excel’s 1-based indexing means the first character is at position 1, and num_chars counts from start_num inclusive.

Extracting Beyond String Length:

// A1 contains: "Test"
=MID(A1, 2, 100)   // Returns: "est" (not an error, just returns what's available)

This behavior is actually useful—you don’t need to calculate exact remaining length when extracting “everything from position X.”

MID vs LEFT vs RIGHT

Choose the right function for the job:

Function Use When Example
LEFT Extracting from start First 3 characters of a code
RIGHT Extracting from end File extensions, last 4 digits
MID Extracting from middle or dynamic position Parsing structured data with delimiters

Same Task, Three Approaches:

// A1 contains: "2024-03-15"
// Extract month ("03")

// Using MID (most explicit):
=MID(A1, 6, 2)

// Using RIGHT + LEFT (awkward):
=LEFT(RIGHT(A1, 5), 2)

// Using MID with FIND (most robust):
=MID(A1, FIND("-", A1) + 1, 2)

For fixed-position data, MID with hardcoded positions is fastest. For varying formats, MID with FIND/SEARCH adapts to changes.

Performance Consideration: All three functions perform similarly on modern Excel. Choose based on readability and maintainability, not micro-optimization.

The real power of MID emerges when combined with other text functions. A formula like =VALUE(TRIM(MID(A1, FIND(":", A1) + 1, FIND("|", A1) - FIND(":", A1) - 1))) might look complex, but it reliably extracts and converts numeric values from inconsistent text data—something you’ll do constantly with real-world datasets.

Master MID by practicing with your actual data. Start with simple fixed-position extractions, then graduate to dynamic formulas using FIND. Once you internalize Excel’s 1-based indexing and understand how num_chars behaves at string boundaries, MID becomes an indispensable tool for data parsing and transformation.

Liked this? There's more.

Every week: one practical technique, explained simply, with code you can use immediately.