Skip to content

Excel function · Text

Excel MID function

MID takes a given number of characters from inside a text, starting at the position you choose: the size in the middle of a product code, the year in an invoice number, the city in brackets.

In Turkish Excel: PARÇAAL

What it does

MID needs three things: the text, the position of the first character to take and how many characters to take. Counting starts at 1, so =MID("KBL-1525-SY",5,4) starts at the fifth character, takes four and returns "1525".

If the middle part is not in the same place on every row, calculate the start with FIND: the position of the first hyphen plus one is the first character of the part. A generous num_chars (say 100) also works, because MID does not complain when it runs past the end; it just returns the characters that are left.

If the start is always 1, LEFT reads better; if the part sits at the end, use RIGHT. In Microsoft 365, TEXTBEFORE and TEXTAFTER together can also return the text between two delimiters.

Syntax

English Excel=MID(text, start_num, num_chars)
Turkish Excel=PARÇAAL(metin; başlangıç; karakter_sayısı)

Arguments in square brackets are optional. English Excel separates arguments with commas (,) and uses a dot for decimals; Turkish Excel uses semicolons (;) and a decimal comma. Excel shows function names in its own language when it opens the file.

Arguments

ArgumentRequiredDescription
textRequiredThe text to take characters from, or a cell.
start_numRequiredThe position of the first character to take; the first character of the text is 1. If it is beyond the end of the text, the result is empty text; it cannot be less than 1.
num_charsRequiredHow many characters to take. If this runs past the end, only the remaining characters are returned. It cannot be negative.

Examples

1Take the size from the middle of a code

Characters 5 to 8 of each cable code are the size code. The codes have the same length, so the start is 5 and the number of characters is 4.

B2fx=MID(A2,5,4)
Take the size from the middle of a code: example table
AB
1Product CodeSize
2KBL-1525-SY1525
3KBL-1540-KR1540
4KBL-2525-SY2525
5KBL-0610-MV0610
  • B2 (filled down to B5)=MID(A2,5,4)

B2 shows 1525 and B5 shows 0610. The result is text, so the leading zero is kept.

We recalculated this example in real Excel (Microsoft 365, 16.0) and compared the results: they match.

2Split out the city in brackets

Each customer name ends with the city in brackets. The start is one after the opening bracket; the length is the distance between the two brackets minus one.

B2fx=MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1)
Split out the city in brackets: example table
AB
1CustomerCity
2Brown & Sons Ltd (Leeds)Leeds
3Northgate Supplies (York)York
4Harbour Trade (Bristol)Bristol
5Star Market (Manchester)Manchester
  • B2 (filled down to B5)=MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1)

The city names have different lengths, but every row returns only the text inside the brackets: B2 shows Leeds and B3 shows York.

We recalculated this example in real Excel (Microsoft 365, 16.0) and compared the results: they match.

3Get the year from numbers with prefixes of different lengths

The prefix of each document number has two to four letters, but the year always comes after the first hyphen. FIND calculates the start.

B2fx=MID(A2,FIND("-",A2)+1,4)
Get the year from numbers with prefixes of different lengths: example table
AB
1Document NoYear
2INV-2025-00422025
3RTN-2024-00072024
4PO-2025-01132025
5CRED-2024-09902024
  • B2 (filled down to B5)=MID(A2,FIND("-",A2)+1,4)

B3 shows 2024 and B4 shows 2025. A fixed =MID(A2,5,4) would cut the rows with shorter or longer prefixes in the wrong place.

We recalculated this example in real Excel (Microsoft 365, 16.0) and compared the results: they match.

Common errors and fixes

#VALUE!

Cause: start_num is less than 1 or num_chars is negative, or the FIND that calculates the start did not find what it was looking for.

Fix: Check that every row contains the delimiter, and wrap the formula in IFERROR if needed.

Empty result

Cause: start_num is larger than the length of the text. Usually the position was calculated wrongly or the text is shorter than expected.

Fix: Compare the position with LEN and check that the delimiter is spelled correctly.

Shifted part

Cause: The codes have different lengths, so a fixed start cuts some rows in the middle of the part.

Fix: Calculate the start from the delimiter instead of typing it: =MID(A2,FIND("-",A2)+1,4).

Good to know

  • The result is text. To calculate with digits taken from the middle, use =--MID(A2,5,4).
  • To find the second delimiter, start the search one character after the first: =FIND("-",A2,FIND("-",A2)+1).

In Nexell

Get Nexell to do it from a sentence

Type this in Nexell

Move the city in brackets in the customer name into a separate City column

Convert to table

Bring your customer list into the tool and type this. Nexell builds the City column with real Excel text formulas and shows it in the preview first; in the downloaded file, the city updates when you edit the name.

Nexell uses AI to understand the request and builds the result with real Excel formulas; the formula may differ from the example on this page. You see a preview first and nothing changes until you press Apply; formulas stay live in the downloaded .xlsx file.

Free account · no card needed · 30 credits a month

Frequently asked questions

How do I extract text between two characters with MID?

The start is the position of the first character plus one; the length is the difference between the two positions minus one. For text in brackets: =MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1). In Microsoft 365 it is shorter: =TEXTBEFORE(TEXTAFTER(A2,"("),")").

What is the difference between MID and LEFT?

LEFT always starts at the first character; with MID you choose the start. =MID(A2,1,3) and =LEFT(A2,3) return the same result.

Related functions

All text functions →

Stop memorising formulas. Describe them.

Bring your table into the tool and say what you need; Nexell builds the formula and shows it in a preview.

Try it free