Skip to main content

MID

The MID function returns the given number of characters from a string starting from the specified position.

This function can be useful when you need to extract part of the text from a longer string.

Syntax​

MID(string, start_num, num_characters)

ArgumentDescriptionPermitted values
stringText string containing the fragment to be extractedText string or reference to a cell containing text
start_numNumber of the character in the text string from which the extracted fragment beginsInteger ≥1 or a reference to a cell containing a number
num_charactersLength of the fragment to be extractedInteger >0 or a reference to a cell containing a number

Examples of use​

Retrieving a substring

=MID("Hello, world!", 1, 5)

Returns “Hello” because it extracts 5 characters starting from the 1st position.

Extraction using variables

If cell A1 contains the text “Spreadsheet,” you can use:

=MID(A1, 3, 4)

The formula will return “read” starting from the 3rd position and extract 4 characters.

Notes​

  • If the start_num is greater than the length of the string, the function will return an empty string.
  • If the num_characters argument is greater than the number of characters remaining in the string, the function will return all remaining characters.