Arte SheetsLearn. Try. Understand.

Cleaning imported data

MID function: extract a middle code segment while keeping leading zeros

Slice a fixed-position middle segment such as 482 or 035 out of product codes like AA-482-Z using one-based character positions.

Three-digit batch segments starting at character 4

In structured part codes AA-482-Z, BB-305-Q, and CC-035-R, characters 1–2 are the family, character 3 is a hyphen, and characters 4–6 are the three-digit batch code.

Part code (A)Middle segment (pos 4, len 3)
AA-482-Z482
BB-305-Q305
CC-035-R035
A-9

Count positions starting at 1, including hyphens

MID(text, start_num, num_chars) begins counting at 1—never 0. In AA-482-Z, A is 1, A is 2, - is 3, and 4 is position 4. Requesting 3 characters from position 4 returns "482". For CC-035-R it returns "035" as text, preserving the leading zero.

=MID(A2,4,3)

Short inputs, zero length, and invalid arguments

If a code is shorter than start_num—such as A-9 (3 characters) in A5—MID(A5, 4, 3) returns empty text ("") cleanly. Requesting 0 characters (MID(A2, 4, 0)) also returns "". However, start_num less than 1 or a negative num_chars returns #VALUE!.

Try the example

Use the original values or change them to test your understanding.

Further reading