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

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

**Excel:** `=MID(A2,$E$1,$G$1)` (Excel 2024 and Microsoft 365)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F | G |
| --- | --- | --- | --- | --- | --- | --- |
| Invoice number | Year |  | Start | 5 | Length | 4 |
| INV-2026-00142 |  |  |  |  |  |  |
| INV-2025-00981 |  |  |  |  |  |  |
| INV-2026-01007 |  |  |  |  |  |  |
| INV-2024-00033 |  |  |  |  |  |  |
| INV-2026-00560 |  |  |  |  |  |  |

Formula in B2, filled to B6: `=MID(A2,$E$1,$G$1)`

Result: 2026; 2025; 2026; 2024; 2026

## 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.

## Other ways

- `=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")`: 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.

## 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.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/extract-characters-from-middle
