
Extracts a chosen number of characters from any position inside a text string.
The Excel MID function returns a specified number of characters from the middle of a text string. You choose where to start and how many characters to take. For example, =MID("ABC-123-XYZ",5,3) returns "123".
MID is the most flexible of the three basic extraction functions. LEFT starts from the beginning, RIGHT starts from the end, and MID can start anywhere you specify.
Returns a part of a text string based on a start position and a length.
Returns the extracted characters as text.
=MID(text, start_num, num_chars)
MID needs three arguments. text is the source value. start_num tells Excel where to begin. num_chars tells Excel how many characters to return from that position.
Use the extraction function that matches where your target text sits in the string. MID is the best choice when the text is in the middle or when the start position has to be calculated.
| Function | Starts From | Use When |
|---|---|---|
LEFT |
The first character | The needed text is at the beginning |
MID |
A position you choose | The needed text is in the middle |
RIGHT |
The last character | The needed text is at the end |
FIND / SEARCH |
- | You first need to locate a delimiter |
MID works well when the segment you need always begins at the same position. If a code always stores the year in characters 5 to 8, MID can extract it directly with fixed numbers.
When the position changes from row to row, MID is often paired with FIND. FIND locates a delimiter such as a hyphen, and MID starts right after that delimiter. This makes the formula adapt to different prefix lengths.
When the target segment always sits in the same place, MID is straightforward. You just give the start position and the number of characters to return.
=MID("ABC-123-XYZ", 5, 3) // "123"
=MID("ENG-2025-Q1", 5, 4) // "2025"
In cell F1, use MID to extract "123" from A2 ("ABC-123-XYZ"). The numbers start at position 5 and are 3 characters long.
If the phone number format is consistent, the area code is always in the same place. In (555) 000-1111, the three digits begin at position 2, so MID can return them directly.
=MID("(555) 000-1111", 2, 3) // "555"
In cell F2, use MID on A3 ("(555) 000-1111") to extract just the 3-digit area code, starting at position 2.
MID can sit inside a comparison or an IF formula when a certain segment of the string has meaning. That is useful for testing batch codes, department codes, or other structured parts of an identifier.
=MID(A4, 4, 3)="789"
=IF(MID(A4, 4, 3)="789", "Priority", "Standard")
In cell F3, check if the segment starting at position 4 of A4 is exactly "789". Formula: =MID(A4,4,3)="789".
When the prefix length changes, a fixed start position will break. Using FIND lets MID calculate the correct starting point from the actual text, so the formula still works when the prefix gets longer or shorter.
=MID(A4, FIND("-",A4)+1, 3)
// "ID-789-X" -> "789"
In cell F4, combine MID and FIND to extract the 3 characters after the first hyphen in A4, regardless of prefix length.
MID works with text, numbers, and dates, but it always extracts from the stored text form of the value. If you need to extract from a displayed format, convert the value with TEXT first.
MID returns characters from any position in a text string.=MID(text, start_num, num_chars).Tell your friends about this post