Excel MID Function
The MID function in Microsoft Excel extracts a specified number of characters from the middle of a text string, starting at a given position. It is useful for parsing data, such as extracting specific segments from codes or text.
Key Topics
Overview of MID Function
The MID function retrieves a substring from a text string, based on a starting position and length. It is commonly used in data cleaning or to extract specific portions of text, like batch numbers or area codes.
MID Function Syntax
The syntax for the MID function is as follows:
Syntax: =MID(text, start_num, num_chars)
Parameters:
- text: The text string to extract from (required).
- start_num: The starting position for extraction (required).
- num_chars: The number of characters to extract (required).
Implementation Examples
Below are examples of how to use the MID function in different scenarios.
Example 1: =MID(A2, 4, 2)
— Extracts 2 characters from A2 starting at position 4.
Example 2: =MID(B2, 2, 3)
— Extracts 3 characters from B2 starting at position 2.
Example 3: =MID(A2, FIND("-", A2)+1, 4)
— Extracts 4 characters after the hyphen in A2.
Sample Dataset (Excel-style View)
Below is a demo dataset styled like Excel, showing how the MID function can be used to extract batch codes from product IDs.
A | B | |
---|---|---|
1 | Product ID | Batch Code |
2 | LAP12345 | =MID(A2, 4, 2) |
3 | PHN67890 | =MID(A3, 4, 2) |
4 | TAB45678 | =MID(A4, 4, 2) |
5 | MON11223 | =MID(A5, 4, 2) |
6 | PRT33445 | =MID(A6, 4, 2) |
Note: In the dataset, column B uses =MID(A2, 4, 2)
to extract two characters from the Product ID in A2, starting at position 4, representing the batch code (e.g., 12 for LAP12345). The formula is applied to each row for consistent extraction.
Key Takeaways
- The MID function extracts characters from the middle of a text string.
- It requires a text string, starting position, and number of characters.
- It can be combined with FIND for dynamic extractions, e.g., after a delimiter.
- Common uses include parsing batch codes, phone numbers, or identifiers.
- The sample dataset demonstrates MID applied to extract batch codes from product IDs.