Description
Use this function to extract a specific number of characters from the middle of a text string, starting at a specified position. Supported in Chains.
MID is useful for extracting substrings, parsing data, and manipulating text in various ways.
Syntax
MID(text, start_num, num_chars)
Inputs
This function accepts the following arguments:
| Name | Required | Description | Valid input |
|---|---|---|---|
text |
Yes | The text string containing the characters you want to extract. | A text string, or a reference to a cell containing text. |
start_num |
Yes | The position of the first character you want to extract in text. | A positive integer, a cell reference that contains a positive integer, or a formula which results in a positive integer. |
num_chars |
Yes | The number of characters you want MID to return from text. | A positive integer, a cell reference that contains a positive integer, or a formula which results in a positive integer. |
Example
Sample Data
A |
B |
||
|---|---|---|---|
1 |
1 |
Eggplant goulash |
|
2 |
2 |
123-45-6789 |
|
3 |
3 |
ABCDEFGHIJKLMNOP |
|
4 |
4 |
Mid Example |
Sample Formulas
| Use case | Formula | Explanation and Result |
|---|---|---|
| Extract a chunk of text from the middle of a string, given a starting position and length. | =MID(B1, 4, 5) |
Starts at the 4th character of "Eggplant goulash" and returns the next 5 characters. Result: plant |
| Pull a short segment out of a formatted identifier, like part of a SSN-style number. | =MID(B2, 5, 2) |
Starts at the 5th character of "123-45-6789" and returns the next 2 characters. Result: 45 |
| Extract a substring from a fixed-width block of text. | =MID(B3, 2, 5) |
Starts at the 2nd character of "ABCDEFGHIJKLMNOP" and returns the next 5 characters. Result: BCDEF |
| Extract the first few characters of a text string, starting from the beginning. | =MID(B4, 1, 3) |
Starts at the 1st character of "Mid Example" and returns the next 3 characters. Result: Mid |
| Extract a fixed number of characters from the end of a string, without knowing its exact length in advance. | =MID(B1, LEN(B1)-3, 4) |
Calculates the length of "Eggplant goulash" to find a starting position 3 characters from the end, then returns the following 4 characters. Result: lash |
Notes
- If
start_numis greater than the length of text, MID returns an empty string. - If
start_numis less than 1, MID treats it as 1. - If
num_charsis negative, MID returns a #VALUE! error. - If
num_charsis greater than the number of characters from start_num to the end of text, MID returns all characters from start_num to the end of text. - MID counts each character, including spaces and punctuation.
Tips
- Combine MID with FIND or SEARCH to extract text based on the position of specific characters.
- Combine MID with LEN to extract a specific number of characters from the end of a string.
- MID can be nested inside other text functions for more complex text manipulation.
- MID is useful for extracting specific fields when working with fixed-width data,
- MID is case-sensitive, it treats uppercase and lowercase letters as different characters.