Excel tutorial
/

Functions

Advanced

Excel SORT function: sort a table automatically with a formula

The Excel SORT function sorts a table with a formula and re-sorts when the source changes: sort_index, descending order, rankings, SORT+FILTER and common traps.

The Данные → Сортировка command sorts a table once and in place: when a new score comes in you sort again by hand, and the original order is lost. The SORT function leaves the source alone — it builds a sorted copy next to it with a formula and re-sorts it on every change.

Where it helps: student rankings, top sales managers, the largest orders, the latest payments. The source table is for data entry; the SORT result is for display and reporting.

SORT is a dynamic array function: the result spills into neighbouring cells. It works in Excel 2021 and Microsoft 365.

Книга1 - Excel
—☐✕
D2fx=СОРТ(A2:B7;2;-1)
ABCDEF
1StudentScoreRankingScore
2Aziz78Dilnoza95
3Dilnoza95Sardor91
4Javohir64Madina88
5Madina88Aziz78
6Sardor91Nodira72
7Nodira72Javohir64
8
ГотовоСреднее: 81,3333Количество: 12Сумма: 488
One formula, a whole ranking. The source (A:B) is untouched, while D:E is sorted by score, highest first

Syntax

=СОРТ(array; [sort_index]; [sort_order]; [by_col])

  • array — the range to sort, without the header: A2:B7.
  • sort_index — the column number inside array to sort by. Omitted means 1 (the first column).
  • sort_order — 1 for ascending (A→Z, smallest to largest), -1 for descending. Omitted means 1.
  • by_col — FALSE (default) sorts rows; TRUE sorts columns (for a horizontal table).

The shortest form, =СОРТ(A2:A7), sorts one column alphabetically.

Building a ranking table

1

Choose where the result goes and type the headers yourself (D1 “Ranking”, E1 “Score”). Keep the cells below empty — the result spills into them.

2

Select D2 and click Формулы → Ссылки и массивы → SORT.

Книга1 - Excel
—☐✕
ФайлГлавнаяВставкаРазметка страницыФормулыДанныеРецензированиеВидСправка
Вставить функциюАвтосуммаФинансовыеЛогическиеТекстовыеДата и времяСсылки и массивыМатематические
Библиотека функций
Диспетчер имён
Определённые имена
D2fx
ABCDEF
1StudentScoreRankingScore
2Aziz78
3Dilnoza95
4Javohir64
5
Готово

3

Array — A2:B7, Sort_index — 2 (score is the 2nd column of the array), Sort_order — -1 (largest first). Leave By_col empty. OK.

Книга1 - Excel
—☐✕
D2fx=СОРТ(A2:B7;2;-1)
ABCDEF
1StudentScoreRankingScore
2Aziz78Dilnoza95
3Dilnoza95Sardor91
4Javohir64Madina88
5Madina88Aziz78
6Sardor91Nodira72
7Nodira72Javohir64
8
Готово

4

Now change a score in the source: Javohir retook the exam and got 97. The ranking rebuilds itself — Javohir moves to first place.

Книга1 - Excel
—☐✕
B4fx97
ABCDEF
1StudentScoreRankingScore
2Aziz78Javohir97
3Dilnoza95Dilnoza95
4Javohir971Sardor91
5Madina88Madina88
6Sardor91Aziz78
7Nodira72Nodira72
8
Готово
No need to re-sort by hand
Книга1 - Excel
—☐✕
C2fx=СОРТ(A2:A7)
ABCD
1NameA → Z
2SardorAziz
3AzizDilnoza
4NodiraJavohir
5DilnozaMadina
6MadinaNodira
7JavohirSardor
8
ГотовоКоличество: 6
Example 1: the simplest case — one column in alphabetical order. No optional arguments: column 1, ascending
Книга1 - Excel
—☐✕
D2fx=СОРТ(A2:B6;1;-1)
ABCDEF
1DateAmountLatestAmount
210.01.20251 200 00013.02.2025640 000
302.02.2025850 00002.02.2025850 000
415.01.20252 300 00023.01.20251 750 000
513.02.2025640 00015.01.20252 300 000
623.01.20251 750 00010.01.20251 200 000
7
ГотовоСреднее: 696841Количество: 10Сумма: 6968410
Example 2: payments by date, newest on top. Note: SORT doesn’t carry formatting — give D:E the date and number formats yourself
Книга1 - Excel
—☐✕
E1fx=ИНДЕКС(СОРТ(A2:B7;2;-1);1;1)
ABCDEF
1StudentScoreWinnerDilnoza
2Aziz78Their score95
3Dilnoza95Last placeJavohir
4Javohir64
5Madina88
6Sardor91
7Nodira72
8
Готово
Example 3: INDEX picks the cell you need from the SORT result — “who’s first, who’s last” without helper columns
Книга1 - Excel
—☐✕
D2fxJavohir
ABCDEF
1StudentScoreResult
2Aziz78Javohir64
3Dilnoza95Nodira72
4Javohir64Aziz78
5Madina88Madina88
6Sardor91Sardor91
7Nodira72Dilnoza95
8Student1Score
9
ГотовоСреднее: 81,3333Количество: 14Сумма: 488
=SORT(A1:B7,2) — the header slipped into the array: text sorts after numbers and ends up at the very bottom

Pro level: multiple keys, SORTBY and top N

  • Two-level sort. Branch first (A→Z), then sales within each branch (largest first): =СОРТ(A2:C20;{1;3};{1;-1}). The curly braces hold the lists of columns and orders.
  • SORTBY sorts by a column that isn’t in the output: =SORTBY(A2:A20;C2:C20;-1) returns only names, ordered by sales. Several keys are easy too: =SORTBY(A2:C20;A2:A20;1;C2:C20;-1).
  • Top 3. In Microsoft 365: =TAKE(СОРТ(A2:B100;2;-1);3). In Excel 2021: =ИНДЕКС(СОРТ(A2:B100;2;-1);ПОСЛЕДОВ(3);{1;2}).
  • Filter, then sort. =СОРТ(ФИЛЬТР(A2:C100;C2:C100="Tashkent");2;-1) — the ranking for one branch.
  • Horizontal tables. With months across columns: =СОРТ(B1:M2;2;-1;ИСТИНА) sorts the columns by row 2.

Try it in the simulator

Type =СОРТ(A2:B7;2;-1) in D2 to build the student ranking. Then change Javohir’s score in B4 to 99 and watch the ranking change. Bonus: type =ИНДЕКС(СОРТ(A2:B7;2;-1);1;1) in G2 to show the winner.

Книга1 - Excel
—☐✕
Буфер обмена
Шрифт
Выравнивание
Число
Стили
Ячейки
Редактирование
✕✓fx
ABCDEFGHIJKLMNOPQRSTUVWX
1StudentScoreRankingScoreWinner
2Aziz78
3Dilnoza95
4Javohir64
5Madina88
6Sardor91
7Nodira72
8
9
10
11
Лист1
Готово

Has ExcelLab been useful?

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

Support us
Previous

137 / 154