How to use MID in Excel: extract text from the middle
MID takes characters from anywhere in a text: a phone’s operator code, the year in a code, a middle name, an email domain. MID + FIND and common traps.
MID cuts a piece out of the middle of a text: “2 characters starting from the 6th”. LEFT takes from the start, RIGHT from the end, and MID from anywhere.
Where it helps:
- The operator code from a phone number “+998 90 123 45 67” — 90.
- The year from a code “TSH-2025-0147” — 2025.
- The first name from “Karimov Aziz Botirovich” — Aziz (MID + FIND).
- The mail provider from “aziz.karimov@gmail.com” — gmail.
Once you know MID, you effectively know LEFT too: =ПСТР(A2;1;3) is the same as LEFT(A2,3).
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Client | Phone | Operator code | |
| 2 | Aziz | +998 90 123 45 671 | 902 | |
| 3 | Dilnoza | +998 93 555 12 34 | 93 | |
| 4 | Javohir | +998 99 777 88 11 | 99 | |
| 5 | Malika | +998 33 210 45 67 | 33 | |
| 6 |
Syntax
=ПСТР(text; start_num; num_chars)
text— the text or a cell containing text.start_num— the character to start from. The first character is 1.num_chars— how many characters to take.
Unlike LEFT and RIGHT, MID has all three arguments required. If start_num is greater than the text length you get an empty string (“”); if it is less than 1 you get #VALUE!. If num_chars exceeds the remaining characters, MID simply takes everything to the end.
Writing MID step by step
1
First, count the characters. “+” and spaces count too: in “+998 90…” the operator code starts at character 6 and is 2 characters long.
| A | B | C | D | E | F | G | H | I | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 4 | 5 | 61 | 7 | 8 | |
| 2 | + | 9 | 9 | 8 | ␣ | 9 | 0 | ␣ | |
| 3 | |||||||||
| 4 | |||||||||
| 5 |
2
Select C2: Формулы → Текстовые → MID.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Client | Phone | Operator code | |
| 2 | Aziz | +998 90 123 45 67 | ||
| 3 | Dilnoza | +998 93 555 12 34 | ||
| 4 | Javohir | +998 99 777 88 11 | ||
| 5 |
3
Arguments: Text — B2, Start_num — 6, Num_chars — 2. Click OK and fill the formula down.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Client | Phone | Operator code | |
| 2 | Aziz | +998 90 123 45 67 | ||
| 3 | Dilnoza | +998 93 555 12 34 | ||
| 4 | Javohir | +998 99 777 88 11 | ||
| 5 | Malika | +998 33 210 45 67 | ||
| 6 |
Example: splitting a code — LEFT, MID and RIGHT together
Document codes follow one pattern: branch (3 letters) – year (4 digits) – sequence number (4 digits). Each part always sits in the same place, so fixed numbers are enough:
=ЛЕВСИМВ(A2;3)— the branch;=ПСТР(A2;5;4)— the year: 4 characters from the 5th (after the first hyphen);=ПРАВСИМВ(A2;4)— the sequence number.
If you need to calculate with the year (say, in COUNTIFS or a comparison), turn it into a number: =ЗНАЧЕН(ПСТР(A2;5;4)).
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Code | Branch | Year | Number | |
| 2 | TSH-2025-0147 | TSH | 2025 | 0147 | |
| 3 | SAM-2024-0032 | SAM | 2024 | 0032 | |
| 4 | BUX-2025-0518 | BUX | 2025 | 0518 | |
| 5 |
The dynamic way: the word between two spaces (MID + FIND)
Official lists in Uzbekistan write names as “Surname Name Patronymic”. The first name is the middle word, and its start and length differ on every row. We find both spaces with FIND:
- 1st space:
=НАЙТИ(" ";A2) - 2nd space:
=НАЙТИ(" ";A2;B2+1)— the 3rd argument starts the search after the 1st space. - Name:
=ПСТР(A2;B2+1;C2-B2-1)— from the character after the 1st space, for as many characters as lie between the spaces.
This is the universal MID + FIND pattern: “the text between two characters”.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Full name | 1st space | 2nd space | Name | |
| 2 | Karimov Aziz Botirovich | 8 | 13 | Aziz | |
| 3 | Rahimova Dilnoza Akmal qizi | 9 | 17 | Dilnoza | |
| 4 | Tursunov Javohir Ilhomovich | 9 | 17 | Javohir | |
| 5 |
Pro level: text between characters and Excel 365 options
Domain from an email. After “@” and up to the first dot that follows it:
=ПСТР(A2;НАЙТИ("@";A2)+1;НАЙТИ(".";A2;НАЙТИ("@";A2))-НАЙТИ("@";A2)-1)
The inner FIND(".",A2,FIND("@",A2)) looks for a dot after the @ — dots in the login (aziz.karimov) don’t get in the way.
The rest of the text. =ПСТР(A2;НАЙТИ(" ";A2)+1;100) returns everything after the first space (“Aziz Botirovich”).
Excel 365:
=ТЕКСТПОСЛЕ(A2;"@")and=ТЕКСТДО(A2;".")— no FIND needed.=ПСТР(A2;ПОСЛЕДОВ(ДЛСТР(A2));1)splits text into single characters and spills them down.
Replacing. To change a piece in the middle of a text, use MID’s partner REPLACE: =REPLACE(B2;6;2;"91") swaps the operator code for 91.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Login | Domain | ||
| 2 | aziz.karimov@gmail.com | aziz.karimov | gmail | |
| 3 | info@excellab.uz | info | excellab | |
| 4 | dilnoza.r@mail.ru | dilnoza.r | ||
| 5 |
Try it in the simulator
Type =ПСТР(B2;6;2) in C2 and fill it down to C5 to get the operator codes. Then type =ПСТР(B2;9;3) in D2, look at the result and explain it yourself: which part of the number is it?
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Client | Phone | Operator | ? | ||||||||||||||||||||
| 2 | Aziz | +998 90 123 45 67 | ||||||||||||||||||||||
| 3 | Dilnoza | +998 93 555 12 34 | ||||||||||||||||||||||
| 4 | Javohir | +998 99 777 88 11 | ||||||||||||||||||||||
| 5 | Malika | +998 33 210 45 67 | ||||||||||||||||||||||
| 6 | ||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.