MID() – Extracts characters from the middle of text

The MID() function returns a specified number of characters from a text string, starting at a given position.

Syntax

MID(text, start, numChars)

  • text: The text string or a cell reference containing the text from which to extract characters.
  • start: The position of the first character to extract (1 = first character).
  • numChars: The number of characters to extract, starting from start. Must be a non-negative integer.

Basic example

MID(T1A1, 3, 4)

Extracts 4 characters from the text in cell T1A1, starting at the 3rd character.

  • If T1A1 = "Example Text": MID(T1A1, 3, 4)"ampl"
  • If T1A1 = "MathGrid": MID(T1A1, 5, 4)"Grid"
  • If T1A1 = "Data" and you request more characters than available: MID(T1A1, 2, 10)"ata" (returns all characters from position 2 to the end)
  • If T1A1 = "Information" and numChars is 0: MID(T1A1, 3, 0)"" (an empty string)

Key features

  • Middle-of-string extraction: Extracts characters from any position within the input text.
  • Handling of numChars: If numChars is 0, it returns an empty string. If numChars is greater than the remaining length of the text, it returns all characters from start to the end.
  • Numeric conversion: If the text argument refers to a cell containing a number, that number will first be converted to text, and then MID() will operate on that text representation.

Practical uses

  • Extracting a substring such as a code, ID, or date from a longer string.
  • Getting a specific part of a name or address.
  • Parsing structured data where information is always in the same position.
  • Isolating a section of a product or serial number.

Common mistakes

  • start is less than 1: The start argument must be 1 or greater (1 = first character).
  • numChars is negative: Providing a negative number for numChars will likely result in an error.
  • numChars is not a number: The numChars argument must be an integer or a cell reference pointing to one.
  • Text argument is a number but expecting string logic: e.g., MID(12345, 2, 2) will treat "12345" as text and return "23".

Report issue

Features, Pricing, Documentation, Support, Login

MathGrid ©

Features,
Pricing,
Documentation,
Support,
Login

MathGrid ©

Back to top Arrow