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.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Ranking | Score | ||
| 2 | Aziz | 78 | Dilnoza | 95 | ||
| 3 | Dilnoza | 95 | Sardor | 91 | ||
| 4 | Javohir | 64 | Madina | 88 | ||
| 5 | Madina | 88 | Aziz | 78 | ||
| 6 | Sardor | 91 | Nodira | 72 | ||
| 7 | Nodira | 72 | Javohir | 64 | ||
| 8 |
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.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Ranking | Score | ||
| 2 | Aziz | 78 | ||||
| 3 | Dilnoza | 95 | ||||
| 4 | Javohir | 64 | ||||
| 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.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Ranking | Score | ||
| 2 | Aziz | 78 | Dilnoza | 95 | ||
| 3 | Dilnoza | 95 | Sardor | 91 | ||
| 4 | Javohir | 64 | Madina | 88 | ||
| 5 | Madina | 88 | Aziz | 78 | ||
| 6 | Sardor | 91 | Nodira | 72 | ||
| 7 | Nodira | 72 | Javohir | 64 | ||
| 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.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Ranking | Score | ||
| 2 | Aziz | 78 | Javohir | 97 | ||
| 3 | Dilnoza | 95 | Dilnoza | 95 | ||
| 4 | Javohir | 971 | Sardor | 91 | ||
| 5 | Madina | 88 | Madina | 88 | ||
| 6 | Sardor | 91 | Aziz | 78 | ||
| 7 | Nodira | 72 | Nodira | 72 | ||
| 8 |
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Name | A → Z | ||
| 2 | Sardor | Aziz | ||
| 3 | Aziz | Dilnoza | ||
| 4 | Nodira | Javohir | ||
| 5 | Dilnoza | Madina | ||
| 6 | Madina | Nodira | ||
| 7 | Javohir | Sardor | ||
| 8 |
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Date | Amount | Latest | Amount | ||
| 2 | 10.01.2025 | 1 200 000 | 13.02.2025 | 640 000 | ||
| 3 | 02.02.2025 | 850 000 | 02.02.2025 | 850 000 | ||
| 4 | 15.01.2025 | 2 300 000 | 23.01.2025 | 1 750 000 | ||
| 5 | 13.02.2025 | 640 000 | 15.01.2025 | 2 300 000 | ||
| 6 | 23.01.2025 | 1 750 000 | 10.01.2025 | 1 200 000 | ||
| 7 |
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Winner | Dilnoza | ||
| 2 | Aziz | 78 | Their score | 95 | ||
| 3 | Dilnoza | 95 | Last place | Javohir | ||
| 4 | Javohir | 64 | ||||
| 5 | Madina | 88 | ||||
| 6 | Sardor | 91 | ||||
| 7 | Nodira | 72 | ||||
| 8 |
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Result | |||
| 2 | Aziz | 78 | Javohir | 64 | ||
| 3 | Dilnoza | 95 | Nodira | 72 | ||
| 4 | Javohir | 64 | Aziz | 78 | ||
| 5 | Madina | 88 | Madina | 88 | ||
| 6 | Sardor | 91 | Sardor | 91 | ||
| 7 | Nodira | 72 | Dilnoza | 95 | ||
| 8 | Student1 | Score | ||||
| 9 |
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.
| 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 | Student | Score | Ranking | Score | Winner | |||||||||||||||||||
| 2 | Aziz | 78 | ||||||||||||||||||||||
| 3 | Dilnoza | 95 | ||||||||||||||||||||||
| 4 | Javohir | 64 | ||||||||||||||||||||||
| 5 | Madina | 88 | ||||||||||||||||||||||
| 6 | Sardor | 91 | ||||||||||||||||||||||
| 7 | Nodira | 72 | ||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 | ||||||||||||||||||||||||
| 11 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.