Excel tutorial
/

Functions

Intermediate

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

Книга1 - Excel
—☐✕
C2fx=ПСТР(B2;6;2)
ABCD
1ClientPhoneOperator code
2Aziz+998 90 123 45 671902
3Dilnoza+998 93 555 12 3493
4Javohir+998 99 777 88 1199
5Malika+998 33 210 45 6733
6
Готово
=MID(B2,6,2) — 2 characters of the phone number (1), starting at the 6th: 90 (2)

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.

Книга1 - Excel
—☐✕
F2fx9
ABCDEFGHI
1123456178
2+998␣90␣
3
4
5
ГотовоКоличество: 2
Top row — the character’s position, bottom row — the character itself (␣ is a space). The code starts at position 6 (1)

2

Select C2: Формулы → Текстовые → MID.

Книга1 - Excel
—☐✕
ФайлГлавнаяВставкаРазметка страницыФормулыДанныеРецензированиеВидСправка
Вставить функциюАвтосуммаФинансовыеЛогическиеТекстовыеДата и времяСсылки и массивыМатематические
Библиотека функций
Диспетчер имён
Определённые имена
C2fx
ABCD
1ClientPhoneOperator code
2Aziz+998 90 123 45 67
3Dilnoza+998 93 555 12 34
4Javohir+998 99 777 88 11
5
Готово

3

Arguments: Text — B2, Start_num — 6, Num_chars — 2. Click OK and fill the formula down.

Книга1 - Excel
—☐✕
C2fx
ABCD
1ClientPhoneOperator code
2Aziz+998 90 123 45 67
3Dilnoza+998 93 555 12 34
4Javohir+998 99 777 88 11
5Malika+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)).

Книга1 - Excel
—☐✕
C2fx=ЗНАЧЕН(ПСТР(A2;5;4))
ABCDE
1CodeBranchYearNumber
2TSH-2025-0147TSH20250147
3SAM-2024-0032SAM20240032
4BUX-2025-0518BUX20250518
5
Готово
The year was converted with VALUE — it is right-aligned and works in calculations; the branch and number are text

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

Книга1 - Excel
—☐✕
D3fx=ПСТР(A3;B3+1;C3-B3-1)
ABCDE
1Full name1st space2nd spaceName
2Karimov Aziz Botirovich813Aziz
3Rahimova Dilnoza Akmal qizi917Dilnoza
4Tursunov Javohir Ilhomovich917Javohir
5
Готово
“Akmal qizi” contains a space too, but the formula only looks at the first two — the name is extracted correctly

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.

Книга1 - Excel
—☐✕
C2fx=ПСТР(A2;НАЙТИ("@";A2)+1;НАЙТИ(".";A2;НАЙТИ("@";A2))-НАЙТИ("@";A2)-1)
ABCD
1EmailLoginDomain
2aziz.karimov@gmail.comaziz.karimovgmail
3info@excellab.uzinfoexcellab
4dilnoza.r@mail.rudilnoza.rmail
5
Готово
Even with a dot in the login (aziz.karimov), the domain comes out right — the dot is only searched for after the @

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?

Книга1 - Excel
—☐✕
Буфер обмена
Шрифт
Выравнивание
Число
Стили
Ячейки
Редактирование
✕✓fx
ABCDEFGHIJKLMNOPQRSTUVWX
1ClientPhoneOperator?
2Aziz+998 90 123 45 67
3Dilnoza+998 93 555 12 34
4Javohir+998 99 777 88 11
5Malika+998 33 210 45 67
6
7
8
9
10
Лист1
Готово

Has ExcelLab been useful?

Support the project and help us release new lessons and exercises.

Support us
Previous

106 / 154