MID Function

Returns characters from the middle of a text value, starting at a position you choose.

Category

Text

Available in

All versions, Microsoft 365

Returns

Text

Taught hands-on in Level 3: Intermediate Lookups & Data Summaries - Text Functions module

Overview

MID extracts a chunk from inside a text string. You give it a starting position and how many characters to take.

It's ideal for codes with a fixed layout, and with FIND it can pull out whatever sits between two markers.

Syntax

=MID(text, start_num, num_chars) Explain

Arguments

ArgumentRequired?What it does
textYesThe text to extract from.
start_numYesThe position of the first character you want. The first character is 1.
num_charsYesHow many characters to return.

Examples

Example 1 — Product number from the middle of a SKU

Northstar's SKUs look like NS-1042-BLU. The product number always starts at character 4 and is 4 long.

B2fx=MID(A2, 4, 4)
AB
1SKUProduct
2NS-1042-BLU1042
3NS-2210-RED2210
4NS-0087-GRN0087
=MID(A2, 4, 4) Explain

Example 2 — Text between two brackets

Pull the department out of each invoice description.

B2fx=MID(A2, FIND("[", A2)+1, FIND("]", A2)-FIND("[", A2)-1)
AB
1DescriptionDepartment
2INV-1001 [Sales]Sales
3INV-1002 [Marketing]Marketing
4INV-1003 [IT]IT
=MID(A2, FIND("[", A2)+1, FIND("]", A2)-FIND("[", A2)-1) Explain
  1. Start one character after the opening bracket.
  2. The length is the gap between the two brackets, minus one.
  3. MID returns just the text inside.
In Microsoft 365, =TEXTBEFORE(TEXTAFTER(A2, "["), "]") reads more naturally.

Common mistakes

  • start_num below 1. MID returns #VALUE! if start_num is 0 or negative — common when a FIND result is off by one.
  • Text, not numbers. "0087" is text. Use --MID(…) or VALUE when you need to calculate with it.

Notes

Kyle Stott

Author

Kyle Stott

Certified Microsoft Excel Expert

Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.