How to Sort by Two Columns in Excel

To sort by two columns in Excel, click any cell in your data, go to Data > Sort, choose the first column under Sort by, select Add Level, choose the second column under Then by, and select OK. Excel sorts by the first column, then sorts rows with the same value by the second column.

Applies to: Excel for Microsoft 365, Excel 2024, 2021, 2019 and 2016 on Windows, Excel for Mac, and Excel for the web.

For example, sorting a staff list by Department and then by Last Name groups everyone by department, with names in alphabetical order inside each department.

Sort by two columns with the Sort dialog

  1. Click any cell inside your data. Excel selects the whole range automatically. If your data has blank rows or columns, select the entire range first.
  2. Select Data > Sort. You can also press Alt + A + S + S.
  3. Make sure My data has headers is ticked, so the header row stays at the top.
  4. Under Column, choose the main column in Sort by, such as Department.
  5. Leave Sort On as Cell Values, and pick an Order, such as A to Z.
  6. Select Add Level. In the new Then by row, choose the second column, such as Last Name, and its order.
  7. Select OK.

Add more levels the same way to sort by three or more columns. Use the up and down arrows in the dialog to change which level comes first, and Delete Level to remove one.

Sort a range quickly without the dialog

Excel’s sort keeps rows that tie in their current order, so you can sort the less important column first:

  1. Click a cell in the second column (Last Name) and select Data > A to Z.
  2. Click a cell in the first column (Department) and select Data > A to Z again.

The result is the same as a two-level sort. The Sort dialog is easier to check and repeat, but this is quick for a one-off.

Sort by two columns with a formula

In Excel for Microsoft 365 and Excel 2021 or later, a formula creates a sorted copy that updates when the source data changes. Your original data stays as it is.

=SORTBY(A2:C100,A2:A100,1,B2:B100,1)

This sorts A2:C100 by column A ascending, then column B ascending. Use -1 instead of 1 for descending order. The SORT function works too: =SORT(A2:C100,{1,2},{1,-1}) sorts by the first column A to Z, then the second Z to A.

Leave enough empty cells below and to the right for the results, or you’ll see a #SPILL! error.

Sort an Excel table by two columns

If your data is formatted as a table, the filter arrows in the header only sort one column at a time. For two columns, click inside the table and use Data > Sort as above. Haven’t made the table yet? Start by creating a table in Excel with multiple columns and rows.

Sort by months, days or a custom order

Alphabetical order puts April before January. To sort in calendar order, open the Sort dialog, choose the column, then set Order to Custom List and pick January, February, March. You can type your own list too, such as High, Medium, Low.

If the sort doesn’t work as expected

  • Headers got sorted into the data: undo with Ctrl + Z, then tick My data has headers.
  • Only one column moved: if Excel shows a Sort Warning, choose Expand the selection. Sorting just the selected column breaks your rows apart.
  • Numbers sort in the wrong order (1, 10, 2): the numbers are stored as text. Select the column and use Data > Text to Columns > Finish to convert them.
  • “All the merged cells need to be the same size”: unmerge cells in the range with Home > Merge & Center before sorting.
  • Part of the data didn’t sort: a blank row or column split the range. Delete the blank rows, or select the full range before sorting.
  • Frozen header rows scroll away: sorting doesn’t affect freezing, so set it up again by freezing multiple columns in Excel.

Frequently asked questions

Can I sort by more than two columns?

Yes. Select Add Level in the Sort dialog for each extra column. Excel supports up to 64 levels.

Does sorting change my formulas?

Formulas move with their rows. References to cells in the same row keep working, but formulas that refer to other rows may point to different data after sorting. Check results after a sort.

Can I sort by color?

Yes. In the Sort dialog, set Sort On to Cell Color or Font Color and choose the color to put on top.

How do I put a single column in alphabetical order?

Click a cell in the column and select Data > A to Z. Other ways to do it are covered in putting Excel in alphabetical order.

Related tasks: sorting Excel by last name, moving a column before you sort, and ranking values from highest to lowest.

Get Our Free Newsletter

How-to guides and tech deals

You may opt out at any time.
Read our Privacy Policy