Function · Text
Excel MID function
The Excel MID function returns characters from the middle of a text value. Characters 5 through 7 of 512-555-0148 are 555.
Syntax =MID(text, start_num, num_chars)
=MID("512-555-0148",5,3)Arguments
| Name | Required | What to pass |
|---|---|---|
| text | Required | The text to slice. |
| start_num | Required | Where to start. The first character is 1, not 0. |
| num_chars | Required | How many characters to return. |
Examples
The exchange in a hyphenated US phone number
=MID(B1,5,3)Result 555
| A | B | |
|---|---|---|
| 1 | Phone | 512-555-0148 |
| 2 | Exchange | 555 |
MID takes a run of characters that is neither the start nor the end. In 512-555-0148, position 1 is 5, position 4 is the hyphen, and positions 5 through 7 are 555. LEFT would need the area code. RIGHT would need the last four. MID is the middle.
The start is 1-based. A start of 0 is a #VALUE! error. If the phone number gains parentheses, every position shifts and a hard-coded 5 is wrong. FIND the hyphen, add 1, and pass that to MID when the punctuation is not stable.