Features of !SEMTools
↑ Navigate Excel tasks and !SEMTools add-in features ↑

Sorting data in Excel

, creator of !SEMToolsUpdated 5 min readTopics: Excel basics
Sort a list in Excel: A to Z, by ending, by length, by word count, upside down
Five ways to sort one list. «By ending» reads every value from its last letter, «Upside down» simply flips the order.

Sorting is one of the most necessary operations with data. It makes analysis much easier, letting you:

  • see the largest and smallest values of numeric ranges;
  • arrange text alphabetically to find the rows you need faster;
  • order events by date and time to understand their sequence and what happened first.

Excel has many sorting tools. Sometimes they’re not enough, though, so I developed a few extra sorting procedures in my !SEMTools add-in. More on them at the end; first, the built-in options.

Sort data with built-in Excel tools

I know and use three ways to sort regular tables on a sheet (not pivot tables): the Filter, the context menu and the Sort dialog on the Data tab. Personally, I like the Filter best.

Sorting with the Filter

To sort with the filter, turn it on for the header row (Data → Filter or Ctrl+Shift+L) and use the drop-down menu of the column you need. It covers most of the basic options:

  • ascending and descending;
  • by fill color and font color;
  • by cell icon.

The context menu

Right-click a selected range → Sort to sort it right in place, without any headers.

An interesting detail: the sort depends on which cell of the selection is active, that is, the side from which you started selecting. Excel sorts by the column of the active cell. Knowing this, you can quickly sort a multi-column range by its rightmost or leftmost column.

The Sort dialog on the Data tab

This is the most universal and flexible sorting tool in Excel. It lets you set exact parameters, use several levels and control the direction. Select the data range or any cell inside the table and go to Data → Sort. In the dialog:

  • Column sets the field to sort by;
  • Sort On sets the type of value: cell values, cell color, font color or conditional formatting icon;
  • Order sets the direction: A to Z or Z to A for text, smallest to largest or largest to smallest for numbers, oldest to newest or newest to oldest for dates.

One of its most useful features is multi-level sorting, by several columns at once. For example, first by region, then within each region by manager, and within each manager by sales from largest to smallest. Add the second and third levels with Add Level: Excel applies them from top to bottom.

You can also sort by color and set the order of colors: first the rows with red fill (critical values), then yellow (warnings), then everything else. The same works with conditional formatting icons, like status indicators or arrows.

A setting many users don’t know about is the direction. By default, Excel sorts rows top to bottom, but in Options you can choose Sort left to right and reorder columns instead. That’s handy for time series, when you need to reorder months or quarters.

Important: if the table has a header row, make sure My data has headers is checked. Otherwise Excel may sort the headers together with the data.

Sorting with formulas in Excel 365

Excel 365 has the SORT and SORTBY functions, which return a sorted copy of the data and update it automatically when the source changes. Sort a table by the second column in descending order:

=SORT(A2:C100,2,-1)
SORT: a sorted copy of the table
E2=SORT(A2:C6,3,-1)
ABCDEFG
1NameRegionSalesNameRegionSales
2AnnaNorth540Bob=SORT(A2:C6,3,-1)South820
3BobSouth820DanEast820
4CleoNorth310AnnaNorth540
5DanEast820CleoNorth310
6EveSouth150EveSouth150

3 is the column to sort by (Sales), −1 means descending. Bob and Dan have equal sales and keep their original order. Change any number on the left and the copy re-sorts itself.

SORTBY can sort by a calculated value that isn’t in the table at all. For example, by the number of characters in the cell, shortest first:

=SORTBY(A2:A100,LEN(A2:A100),1)
SORTBY: sort by a calculated value
D2=SORTBY(A2:A6,LEN(A2:A6),1)
ABCD
1WordLengthShortest first
2banana6=LEN(A2)fig=SORTBY(A2:A6,LEN(A2:A6),1)
3fig3=LEN(A3)kiwi
4kiwi4=LEN(A4)apple
5apple5=LEN(A5)banana
6plum tree9=LEN(A6)plum tree

SORTBY sorts A2:A6 by an array that isn’t in the table — the lengths. Words of equal length would keep their source order. Column B only shows the lengths; the formula doesn’t need it.

In older versions, the same requires a helper column with =LEN(A2), sorting by it and then deleting it.

Special sorting modes in !SEMTools

In my practice I often needed to sort data in the ways below, so I added procedures for them to make life easier. A couple of clicks is always more convenient than creating helper columns and writing formulas:

  • sort a range by word endings, that is, by the last letters in alphabetical order (useful for grouping words with the same suffix);
  • sort by the number of characters;
  • sort by the number of words.

The add-in also has simple sorting of a selected range: A to Z for text, smallest to largest for numbers and dates, and in reverse.

All of them are in CHANGE → Range → Sort: Simple sort, By ending, By length, By number of words and Flip upside down.

Sort ranges by word endings, length or number of words in a couple of clicks, without helper columns.
!SEMTools solves this and hundreds of other tasks right in Excel!

Summary: which sorting method to choose

I hope you found what you were looking for on this page. The Filter is the fastest for everyday sorting, the Sort dialog for multi-level and color sorting, SORT and SORTBY in Excel 365 for a live sorted copy, and !SEMTools for sorting by length, word count or endings without helper columns.