Going Stellar

Home/Google Sheets reference

Google Sheets function · Text

MID in Google Sheets: syntax and examples

MID cuts a fixed number of characters out of a text, starting at a position you choose. It suits codes with a fixed layout, such as SKUs, phone numbers and dates stored as text.

Syntax

MID(string, starting_at, extract_length)

Arguments

ArgumentTypeRequiredWhat it does
stringstringyesThe text to cut from. A number is converted to text first.
starting_atnumberyesThe position of the first character to return, counted from 1.
extract_lengthnumberyesHow many characters to return. A value past the end of the text just returns what is left.

Examples

The examples use this table, starting in A1:

CodeText
SKU-4821-REDGoogle Sheets
ABx
=MID(A2, 5, 4)

Result: 4821

Four characters starting at position 5 of the code: the middle number.

Run in a Google Sheet (English US locale) on .

=VALUE(MID(A2, 5, 4)) + 1

Result: 4822

MID returns text. VALUE turns it into a number before the +1, and makes comparisons with numbers work.

Run in a Google Sheet (English US locale) on .

=MID(A2, SEARCH("-", A2) + 1, 4)

Result: 4821

The start is found with SEARCH, so the formula still works if the prefix changes length.

Run in a Google Sheet (English US locale) on .

=MID(B2, 8, 100)

Result: Sheets

A length larger than the text is fine: you get everything from position 8.

Run in a Google Sheet (English US locale) on .

=MID(12345, 2, 3)

Result: 234

A number is accepted as the string. The three characters from position 2 are 234.

Run in a Google Sheet (English US locale) on .

Common errors

  • Positions start at 1. A starting_at of 0 returns #NUM!, and a negative extract_length returns #VALUE!.
  • A start beyond the end of the text returns an empty string, not an error, so a broken formula can look like a blank cell.
  • The result is always text, even when it looks like a number: MID(A2,5,4)=4821 is FALSE. Wrap it in VALUE before comparing.

Compared with Excel

Same syntax in Excel.

Sources

  1. MID (Docs Editors Help)

Markdown version · All functions