formulastreak

Text function

MID function in Google Sheets and Excel

MID returns characters from the middle of a text: you say where to start and how many to take.

Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet

Syntax

MID(text, start_num, num_chars)

Arguments in [brackets] are optional. Google Sheets writes it MID(string, starting_at, extract_length).

Example

=MID(C2,4,2) reads: From C2 (GB-2041), start at the 4th character and take 2 characters.

Workshop sign-ups · edit E2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultE2 = 20
ABCDE
1NameEmailMember codeCityMiddle
2 mara okafor mara.okafor@example.comGB-2041London20
3JONAS LINDjonas.lind@example.orgSE-1187Malmö
4priya ramanpriya.raman@example.netIN-3302Pune
5Tomás Ruiz tomas.ruiz@example.comES-0419Seville
6elif demirelif.demir@example.orgTR-2750Izmir
7 Kenji MORIkenji.mori@example.netJP-1093Osaka
8sofia rossisofia.rossi@example.comIT-4468Turin
9Leo Brandtleo.brandt@example.orgDE-3321Leipzig

E2 shows 20: characters 4 and 5 of GB-2041 (G, B and - are positions 1 to 3).

How the spreadsheet calculates it

Takes 2 character(s) of C2, starting at character number 4.

  1. 1. MID: Takes 2 character(s) of C2, starting at character number 4.
    • text = `C2`: the cell to cut from
    • start = `4`: the position of the first character to take
    • n = `2`: how many characters to take

More MID examples

  • =MID(C2,4,4)All four digits of the member code: 2041.
  • =MID(B2,FIND("@",B2)+1,100)Everything after the @: example.com.
  • =MID(B2,FIND(".",B2)+1,FIND("@",B2)-FIND(".",B2)-1)The surname between the dot and the @: okafor.
  • =VALUE(MID(C2,4,4))The digits as a number.

Paste any of these into the formula explainer to see it step by step.

Tips

  • Count positions on paper first: the first character is 1, and spaces and punctuation count.
  • Use FIND for start_num when the position varies.
  • A generous num_chars (100) is a simple way to say "to the end".

What MID is used for

Pulling a part number, year or region code out of the middle of an ID, taking surnames from emails, and splitting fixed-width exports where each field always starts at the same position.

Arguments

ArgumentRequiredWhat it is
textYesThe text or cell to cut from, such as C2.
start_numYesThe position of the first character to take; the first character is 1.Watch out: Past the end of the text MID returns empty text; less than 1 gives #VALUE!.
num_charsYesHow many characters to take. Asking for more than are left just returns the rest.Watch out: A negative number gives #VALUE!.

Common mistakes

  • Counting from 0: the first character is position 1.

  • Leaving out num_chars: unlike LEFT and RIGHT, MID needs all three arguments.

  • Hard-coding the start position for texts of different lengths: find it with FIND, as in MID(B2,FIND("@",B2)+1,100) for everything after the @.

In Google Sheets

Google Sheets has MID with the same three arguments, written MID(string, starting_at, extract_length); all three are required in both apps.

Errors you may see with MID

  • #VALUE!: start_num is less than 1 or num_chars is negative, often because a FIND inside didn't find its character.

Questions

How do I extract the text between two characters?

Start one after the first character and take the distance to the second: =MID(B2,FIND(".",B2)+1,FIND("@",B2)-FIND(".",B2)-1) returns okafor from mara.okafor@example.com. More in extract text between two characters.

How do I take everything from a position to the end?

Give num_chars a number bigger than any text in the column, such as 100: MID stops at the end. Or use the exact count: LEN(C2)-3.

Why can't I add up MID's results?

MID always returns text, even when it looks like digits. Wrap it in VALUE: VALUE(MID(C2,4,4)) is the number 2041.

MID or TEXTAFTER?

TEXTAFTER (Excel 2024 and Microsoft 365) finds the cut by a delimiter instead of a position. MID with FIND works in every version and in Google Sheets.

Sources

Official documentation the facts on this page were checked against.

Practise MID on a live sheet

Lesson 23, Cut text: LEFT, RIGHT and MID (Unit 6, Text and dates), has 3 graded exercises, checked instantly, with steps and hints when you're stuck. Pro