Mid
Syntax:¶
MID(text, start_num, num_chars)
- text: The text string from which you want to extract characters.
- start_num: The position of the first character you want to extract. The first character in
textis 1. - num_chars: The number of characters you want to extract from the
text, starting atstart_num.
Description:¶
The MID function in Excel is used to extract a specific number of characters from a text string, starting at a
specified position. This function is particularly helpful when you need to extract substrings from within a longer text
string.
Its flexible parameters allow selection of any subset of the string based on your requirements.
For example:
MID("text", start_num, num_chars) = extracted substring
Examples:¶
=MID("HelloWorld", 1, 5)would return"Hello", extracting the first 5 characters from "HelloWorld".=MID("DataProcessing", 5, 4)would return"Proc", which starts at the 5th character and extracts 4 characters.=MID("ExcelFunctions", 7, 9)would return"Functions", as it starts at the 7th character and continues for 9 characters.=MID("123456789", 4, 3)would return"456", starting at the 4th character and extracting 3 characters.
Notes:¶
- If
start_numis greater than the current length oftext, theMIDfunction will return an empty string (""). - If
start_numis less than 1, Excel will return an error (#VALUE!). - If
num_charsis 0, an empty string ("") is returned. - If
start_num + num_chars - 1exceeds the length oftext, the function will return all characters fromstart_numto the end of thetext. - Use the
MIDfunction when needing to extract substrings dynamically, especially for parsing or cleaning up text data.