Spreadsheet Practice

How to extract characters from the middle of a text string in Excel

Formula (Excel and Google Sheets)

=MID(A2,$E$1,$G$1)

Use MID with a start position and a length: =MID(A2,5,4) returns 4 characters starting at the 5th.

Result on the example
one result per row in B2, filled down to B6
Works in
Excel 2024 and Microsoft 365
Google Sheets
Same formula

See it work

The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.

How it works

MID takes three things: the text, where to start (counting the first character as 1) and how many characters to return. In "INV-2026-00142" the year starts at character 5 and is 4 characters long.

=MID(A2,$E$1,$G$1)

Result"2026"

  1. A2"INV-2026-00142"

    The value in A2.

  2. $E$15

    The value in E1.

  3. $G$14

    The value in G1.

  4. MID(A2,$E$1,$G$1)"2026"

    MID: Characters from the middle of text.

    • textA2"INV-2026-00142"
    • start_num$E$15
    • num_chars$G$14

In Google Sheets

The same formula works in Google Sheets: =MID(A2,$E$1,$G$1). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")2026, 2025, 2026…Excel 365: when the part you need sits between delimiters rather than at a fixed position, split on them instead.

Common mistakes

  • MID needs all three arguments; there is no default length.
  • MID returns text: "2026" is not the number 2026. Use =VALUE(MID(A2,5,4)) or =--MID(A2,5,4) to calculate with it.
  • Fixed positions only work when every value has the same layout. One shorter prefix shifts everything.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Extract characters from the middle of a text string

In B2, extract the characters that start at the position in E1 and run for the length in G1, then fill down to B6.

Questions

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

Give MID a length that is long enough: =MID(A2,10,LEN(A2)).

How do I find the start position automatically?

Use FIND: =MID(A2,FIND("-",A2)+1,4) starts right after the first dash.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.