Field Guide

How to sort data in Excel: alphabetize, dates, and custom sort

Updated

To alphabetize a column in Excel: select a single cell in the column, then choose Data > Sort & Filter > Sort A to Z. For descending order, choose Sort Z to A. Selecting a single cell, rather than highlighting the whole column, lets Excel sort the block of data around it and keep every row together.

Sorting reorders the rows of a range so one column reads in order, alphabetical, numeric, or by date. This guide walks through the one-click A to Z sort, the row-integrity warning that keeps values attached to their rows, sorting by several columns at once, sorting dates the right way, sorting in a custom order such as months or High to Low, sorting by cell or font color, and how to undo a sort. For a formula that re-sorts on its own, jump to the last section.

How do I alphabetize a column?

Select one cell anywhere in the column you want in order, then on the Data tab, in the Sort & Filter group, select Sort A to Z for ascending or Sort Z to A for descending. That single click reorders the whole connected range by that column, and each row travels with it.

A B
1 Name Region
2 Nolan West
3 Adams East
4 Byrne North
5 Meyer South
Before: click one cell in the Name column (A2), then Data > Sort & Filter > Sort A to Z. Excel treats A1:B5 as one block and sorts A2:A5 while carrying each Region in column B along.
A B
1 Name Region
2 Adams East
3 Byrne North
4 Meyer South
5 Nolan West
After Sort A to Z: A2:A5 now reads Adams, Byrne, Meyer, Nolan, and each Region moved with its name (Adams still shows East). Whole rows changed places, not just column A.

Two details matter. First, click one cell, not the column header or the whole column: a single cell lets Excel find the surrounding data and move it as a set, while selecting the column on its own triggers the warning covered in the next section. Second, the full Sort dialog is also reachable from the Home tab, under the Editing group’s Sort & Filter menu, listed there as Custom Sort. In Excel for the web the two buttons read Sort Ascending and Sort Descending instead, but they do the same job.

How do I sort without scrambling the other columns?

This is the mistake that turns a sort into a data-integrity problem. When you select a single cell and sort, Excel reads the connected block of data around that cell and moves every column together, so each row stays intact. The danger comes from selecting less than the full block, usually one whole column, and sorting only that. The sorted column then lands against rows it no longer belongs to.

Excel tries to catch this. Microsoft’s sort page cautions against it directly: “It is possible to sort a range within a range, but it is not recommended, because the result disassociates the sorted range from its original data.” When it senses you are about to sort a column on its own, it stops and offers two choices: Expand the selection, which pulls in the neighboring columns so the rows move as whole units, or Continue with the current selection, which reorders only what you highlighted and splits it from the rest. Choose Expand the selection unless you genuinely want one column reordered in isolation. If a sort has already gone wrong, select Undo straight away.

How do I sort by more than one column?

When the first sort key ties, a second key decides the order inside that tie. The usual shape is group, then order: sort by a Department column to gather each team, then by a Name column to alphabetize within each department. That needs the full Sort dialog rather than the one-click buttons.

Click a single cell in the data, then choose Data > Sort & Filter > Sort. In the dialog, set Sort by to the first column, leave Sort On as Cell Values, and pick the Order (A to Z, Smallest to Largest, or Oldest to Newest). Select Add Level, and a Then by row appears for the next column; set it the same way. You can stack up to 64 columns, and whatever sits higher in the list is applied first, so the top row is the primary key. Select OK to run it.

How do I sort by date?

Select a single cell in the date column, then choose Data > Sort & Filter > Sort Oldest to Newest for ascending order or Sort Newest to Oldest for descending. This only works when the cells hold real dates. Excel stores every date as a serial number behind the display and sorts on that number, so the calendar order comes out right. If a date was typed or imported as text, Excel cannot read it as a date: it sorts the values character by character instead, which is why a column of text dates lands in an order that follows the characters rather than the calendar. The fix is to turn the text into real dates first, which the date format guide walks through.

To sort by the name of a day or month rather than its calendar value, Excel keeps built-in custom lists for the days of the week and the months of the year. A column of month names then sorts January, February, March instead of alphabetically, with nothing to set up. That runs through the Order > Custom List route in the next section.

How do I sort in a custom order?

Alphabetical and numeric order do not fit every column. A Priority column of High, Medium, and Low reads best in that rank, but an A to Z sort would put High first, then Low, then Medium. A custom sort fixes it. In the Sort dialog, set Sort by to the column, then open the Order drop-down and choose Custom List.

Excel ships built-in lists for the days of the week and the months of the year, so those sort by the calendar with no setup. For your own order, such as High, Medium, Low, create the list once: type the values top to bottom in a few cells, select them, go to File > Options > Advanced, scroll down to the General section, select Edit Custom Lists, then Import. (For a short list, Microsoft notes you can type the entries straight into the List entries box instead.) The list then shows up under Custom List whenever you sort.

How do I sort by cell or font color?

If cells are shaded by hand or by conditional formatting, you can sort on the color instead of the value. Select a cell in the column, open Data > Sort & Filter > Sort, and set Sort by to the column. Under Sort On, choose Cell Color, Font Color, or Cell Icon. Then decide where each color goes: under Order, pick the color and whether it moves On Top or On Bottom (for a left-to-right sort, On Left or On Right). There is no default color order, so you build it one color at a time, adding a level with Add Level for each.

One platform note: in Excel for the web the Sort On menu is switched off, because color sorting is not supported there yet, so a color sort has to be run in the desktop app.

How do I undo or remove a sort?

A sort rewrites the range in place, and Excel does not keep the previous order anywhere, so there is no unsort button to switch back. To reverse a sort you just ran, select Undo or press Ctrl+Z before you make other changes. In Excel for the web, the Undo button is on the Home tab. Once the file has been saved and reopened, though, the earlier order is gone unless you kept a copy. The simple safeguard is to add a plain numbering column (1, 2, 3, and so on) before you sort: sorting on that column later restores the original order.

The Sort feature or the SORT function?

The Sort command on the Data tab reorders the cells that are in the range right now, one time, and it changes the saved data. For a result that re-sorts on its own whenever the underlying data changes, Excel has a separate =SORT() function: a dynamic-array formula that spills a sorted copy into new cells and leaves the source list where it is. Microsoft’s own sort page points to the SORT and SORTBY functions for exactly that, and the function is covered in the array formulas guide.

To hide the rows that do not match a condition instead of reordering them, reach for the other half of the Sort & Filter group and filter the data.

The short version

Frequently asked questions

How do I alphabetize a column in Excel?
Select one cell anywhere in the column, then on the Data tab, in the Sort & Filter group, select Sort A to Z for ascending order or Sort Z to A for descending. Clicking a single cell, rather than highlighting the whole column, lets Excel sort the connected block of data around it and keep every row together.
How do I sort without scrambling the other columns?
Click one cell in the data before you sort, not a whole column. Excel then reads the surrounding block and moves each row as a unit. If you select just one column and sort it, Excel warns you that the sorted range will be split from its data and offers two buttons: choose Expand the selection so the neighboring columns come along, not Continue with the current selection, which reorders that one column on its own. If it went wrong, select Undo.
How do I sort by more than one column in Excel?
Click a single cell in the data, then select Data > Sort & Filter > Sort. In the dialog, set Sort by to the first column and pick its Order, then select Add Level to add a Then by row for the next column. You can stack up to 64 columns, and whatever sits higher in the list is applied first, so the top row is the primary sort key. Select OK to run it.
How do I sort by date in Excel?
Select a cell in the date column, then choose Data > Sort & Filter > Sort Oldest to Newest or Sort Newest to Oldest. This only works when the cells hold real dates, which Excel stores as serial numbers and sorts by that number. Dates typed or imported as text sort character by character instead of by the calendar, so convert them to real dates first.
How do I sort in a custom order or by color?
For a custom order, open the Sort dialog, set Sort by to the column, then set Order to Custom List. Excel ships built-in lists for days of the week and months of the year; for your own order, such as High, Medium, Low, create it under File > Options > Advanced > Edit Custom Lists. To sort on formatting, set Sort On to Cell Color or Font Color in the same dialog (this is a desktop feature; Excel for the web disables Sort On).
How do I undo a sort in Excel?
A sort rewrites the range in place and Excel does not store the previous order, so there is no unsort button. To reverse a sort you just ran, select Undo or press Ctrl+Z before making other changes; in Excel for the web the Undo button is on the Home tab. Once the file is saved and reopened the earlier order is gone, so add a plain numbering column before sorting if you may need to restore it.

Catch the errors before they ship

Reviewing a change to a model? Compare the two versions in your browser and see every changed cell, formula, and value. It's free, and nothing leaves your computer.