To sort multiple columns in Excel, select your complete dataset, open Data > Sort, and add a sorting level for each column in priority order. Excel applies the first rule first, then uses each additional rule to sort rows with matching values in the earlier columns. Keep every related column in the selection so each row stays together.
The short version
- Keep rows together: Select the complete dataset before applying a multilevel sort.
- Set the priority: Put the main column first, then add secondary columns below it.
- Match your app: Windows and Mac use Add Level, while Excel for the web uses Add.
- Create a separate result: Use
SORTBYwhen you want an automatically updated sorted output.
| Method or option | Where to start | Use it for |
|---|---|---|
| Windows multilevel sort | Data > Sort | Reordering complete rows in place |
| Windows Home tab entry | Home > Editing > Sort & Filter > Custom Sort | Opening the same sorting controls |
| Windows right-click entry | Sort > Custom Sort... | Opening sorting controls from the dataset |
| Windows keyboard entry | Alt + A, then S, then S | Configuring levels with the keyboard |
| Mac multilevel sort | Data > Sort | Reordering complete rows in place |
| Browser multilevel sort | Data > Custom Sort | Sorting a range or table in your browser |
SORTBY formula | An empty output cell | Creating an automatically updated sorted result |
| Independent list formulas | SORT in separate output columns | Sorting unrelated lists separately |
| Windows custom order | Order > Custom List | Using weekdays, months, or your own sequence |
| Mac custom order | Order > Custom List | Using a defined sequence within a sort |
| Windows formatting rules | Sort On in the sorting dialog | Ordering by cell color, font color, or icon |
| Windows reapply shortcut | Ctrl + Alt + L | Reapplying existing column-sort rules |
| Saved table sort | Home > Editing > Sort & Filter > Reapply | Reusing table criteria after reopening |
Select the full dataset and decide the order
Start by selecting all the data that belongs together, including the columns you are not using as sorting rules. For example, sorting a list by Region and Amount should also move the matching names and dates with those values. If Excel displays a selection warning, select Expand the selection to keep the related cells together.
Decide which column matters most before opening the sorting dialog. A Region ascending rule followed by an Amount descending rule groups rows by region, then puts larger amounts first within each region. The second rule works inside the groups created by the first rule.
Before changing the order, you can copy the worksheet in Excel to keep a separate version. If hidden columns make it difficult to identify your sorting fields, unhide the columns in Excel before choosing the rules.
Sort multiple columns in Excel for Windows
In Excel for Microsoft 365 or Excel 2024 for Windows, select the complete dataset and open Data > Sort. When the first row contains column headings, check My data has headers. Under Sort by, choose your primary column, set Sort On to Cell Values, and choose the required Order.
Select Add Level to create your next rule. Under Then by, choose the secondary column and its order, then repeat for any additional columns. Keep the highest-priority rule at the top and select OK to apply the complete sort.
You can reach the same controls through Home > Editing > Sort & Filter > Custom Sort. Another entry point is to right-click inside the dataset and select Sort > Custom Sort.... Configure all the column rules in that dialog, then select OK.
For keyboard access in English-language Excel for Microsoft 365 or Excel 2024 for Windows, select the dataset, then press Alt + A, then S, then S in sequence. Use Tab to reach Sort by, Sort On, and Order, and use the arrow keys to choose values. Use Tab to reach Add Level and press Enter for each additional rule, then move to OK and press Enter.
Add sorting levels in Excel for Mac
In Excel for Microsoft 365 for Mac or Excel 2024 for Mac, select your dataset and open Data > Sort. When your selection includes a header row, check My list has headers. Choose the primary column beside Sort by, select Values under Sort On, and choose the Order.
Click Add Level for the next column and complete its sorting criteria. Continue adding levels in priority order, then select OK. Selecting the complete dataset keeps the values in each row together.
Use Custom Sort in Excel for the web
In Excel for the web, select the dataset and open Data > Custom Sort. Choose your first column under Sort by, then set Order to Sort Ascending or Sort Descending. Select Add to include another column.
Set each additional column and direction before applying the sort. Use the Up or Down arrow to change a rule's priority, keeping the main column first. Select OK when the rules are in the order you want.
Create an automatically updated result with SORTBY
Use SORTBY when you want a sorted result in a separate area. You can use it in Excel for Microsoft 365 and Excel 2024 on Windows and Mac, Excel for the web, and Excel on iPhone, iPad, and Android devices. Keep the output area empty so the returned rows can spill into neighboring cells.
For source data in A2:D100, select an empty cell outside the source table and enter the following formula. It returns all four columns, sorted first by column A ascending and then by column C descending.
=SORTBY(A2:D100,A2:A100,1,C2:C100,-1)Press Enter to calculate the result. The first argument identifies the complete data to return, and each following pair supplies a sorting range and its direction. Use 1 for ascending and -1 for descending, replacing the example ranges with your own and adding further range and order pairs for more sorting columns.
For unrelated lists whose rows do not need to stay connected, use SORT in separate output columns. Enter the following formula in an empty output column to sort the list in column A.
=SORT(A2:A100)Copy the formula horizontally to produce the corresponding formulas for columns B, C, and beyond. Each copied formula sorts its source column independently. Use that approach only for separate lists, since the output no longer preserves relationships between values that originally shared a row.
Choose custom orders and formatting rules
For a sort that needs weekday, month, or another defined order in Excel for Microsoft 365 or Excel 2024 for Windows, open Data > Sort. On the relevant level, open Order > Custom List, choose the list, and select OK. Add other column levels as needed, then select OK to apply the sort.
To create your own list in those Windows editions, enter its values vertically and select them. Open File > Options > Advanced, find General, and select Edit Custom Lists.... Select Import, then OK.
In Excel for Microsoft 365 for Mac or Excel 2024 for Mac, create a list through Excel > Preferences > Formulas and Lists > Custom Lists > Add. Enter comma-separated values, select Add, and close the dialog. Return to Data > Sort and choose Order > Custom List for the relevant level. Choose your list and select OK, add other levels as needed, then apply the sort.
In Excel for Microsoft 365 or Excel 2024 for Windows, you can also combine value rules with formatting rules through Data > Sort. Set a level's Sort On to Cell Color, Font Color, or Cell Icon, choose the format, and select On Top or On Bottom. Select Add Level for the next format or column, then select OK.
Fix the sort order and reapply saved rules
If the result looks wrong, examine rows with matching values in the primary column to check the secondary order. Reopen the sorting dialog and check the priority of the levels and each column's direction. For a long dataset, you can freeze rows or columns in Excel to keep headings visible while reviewing it.
When edited data needs sorting again, select a cell in the previously sorted range or table. In English-language Excel for Microsoft 365 or Excel 2024 for Windows, press Ctrl + Alt + L to reapply the existing column-sort criteria. If your intended priority has changed, update the rules in the sorting dialog before applying them again.
To retain sorting rules after reopening a workbook, apply the sort to an Excel table and save the workbook. Tables retain sort criteria with the workbook, while ordinary ranges do not retain those criteria across reopening. In Excel for Microsoft 365 or Excel 2024 for Windows and Mac, select a table cell and open Home > Editing > Sort & Filter > Reapply to apply the saved criteria again.
Frequently Asked Questions
Can Excel distinguish uppercase and lowercase text when sorting?
Yes, in Excel for Microsoft 365 or Excel 2024 on Windows and Mac, open Data > Sort > Options and select Case sensitive. In Excel for the web, open Data > Custom Sort > Options and select Case sensitive. Select OK, finish your column rules, and apply the sort.
How do you rearrange whole columns from left to right?
For a range in current Windows or Mac desktop Excel, open Data > Sort > Options and choose Sort left to right under Orientation. In Excel for the web, also choose Sort left to right under Orientation, starting from Data > Custom Sort > Options. Choose the row and order, add further row criteria as needed, and apply the sort. If your data is in an Excel table, convert it to a range first.
Why can sorting fail on a protected worksheet?
Locked cells anywhere in the sortable range prevent sorting, even when sorting is permitted. Before protecting the sheet in Excel for Microsoft 365 or Excel 2024 desktop, select the complete sortable range, open Format Cells > Protection, uncheck Locked, and select OK. Open Review > Protect Sheet, select Sort under Allow all users of this worksheet to, and select OK.
Does sorting a PivotTable rearrange the original data?
No, when you sort a PivotTable, you change the grouped report fields without rearranging the underlying source records. In current Windows or Mac desktop Excel, select the Row Labels or Column Labels arrow, choose the field, and select Sort A to Z or Sort Z to A. Repeat for another field as needed; desktop Excel also offers More Sort Options.