The MID function in Google Sheets is a powerful tool designed to extract a substring from a given text string. This function is particularly useful when you need to obtain a specific segment of text, whether it’s for data manipulation, analysis, or presentation purposes. By specifying the starting position and the length of the substring, users can easily retrieve the desired text from within larger strings.
Syntax
MID(text, start_num, num_chars)
- text: The original text string from which to extract the substring.
- start_num: The position within the text to begin extraction (1-based index).
- num_chars: The number of characters to extract from the text starting at start_num.
Example #1
=MID("Google Sheets", 1, 6)
This function extracts the first 6 characters from “Google Sheets”, resulting in “Google”.
Example #2
=MID("Data Analysis", 6, 7)
This command retrieves 7 characters starting from the 6th position of “Data Analysis”, yielding “Analys”.
Example #3
=MID("Welcome to Google Sheets!", 10, 5)
This extracts 5 characters beginning from the 10th position, resulting in “Google”.
Error handling
- VALUE!: Indicates that the start_num parameter is less than 1 or not a number.
- REF!: Occurs when start_num exceeds the length of the text string, making it impossible to extract the specified characters.
- NUM!: Arises if the num_chars parameter is negative or if the resulting substring extends beyond the length of the original text.