How to Sort a Spreadsheet in Excel
In this article
Sorting a spreadsheet in Excel reorganizes your data based on specific columns, making it easier to read, analyze, and find trends. You can sort data alphabetically, numerically, or by date. To sort, select the data you want to organize, go to the Data tab on the ribbon, and click the Sort button to open the Sort dialog box where you can choose your criteria. This process requires clean data; ensure your headers are in the first row and there are no merged cells in the range you intend to sort.
What You'll Need
- A computer with Microsoft Excel installed (Excel 2016, 2019, 2021, or Microsoft 365 are recommended for the best experience).
- A spreadsheet containing data with at least two columns (one for the data and one for the category you want to sort by).
- A basic understanding of how to select text in a document.
Step-by-Step
- Select your data. Click and drag your mouse to highlight the entire block of data you wish to sort. This includes the column headers (the top row) and all the rows below them. If you have data in other parts of the sheet that you do not want to move, do not include those cells in your selection.
- Locate the Data tab. Look at the top ribbon menu of Excel. You will see several tabs such as File, Home, Insert, and Page Layout. Click on the Data tab. This tab contains all the tools for manipulating and analyzing your data.
- Find the Sort button. On the right side of the Data tab, you will see a large button labeled Sort. It usually features an icon that looks like a Z to A or A to Z arrow. Click this button. This action will open the Sort dialog box.
- Choose the sort column. In the Sort dialog box, look for the Sort by dropdown menu (usually at the top). Click this menu to see a list of all the column headers you selected in Step 1. Select the header of the column you want to use to organize your data. For example, if you have a list of sales figures, you might choose the "Sales" column.
- Select the sort order. Immediately below the Sort by dropdown, you will see a second dropdown menu labeled Sort On. This controls whether Excel looks at cell values, cell color, font color, or cell icons. For most standard sorts, you will leave this set to Values.
- Set the direction. The third dropdown menu, labeled Order, determines the direction of the sort. You can choose A to Z for ascending order (text from A to Z or numbers from smallest to largest) or Z to A for descending order (text from Z to A or numbers from largest to smallest). Select your preferred option.
- Understand the Sort Options. To the right of the Order dropdown, click the Options... button. This reveals a dialog box where you can set the sort case sensitivity (A and a are treated as the same letter by default) or set the sort order for days and months (e.g., January before February vs. February before January). For most basic tasks, you can leave these settings as default.
- Click OK. Once you have configured the Sort by, Sort On, and Order fields to your liking, click the OK button at the bottom of the dialog box. Your spreadsheet will instantly rearrange itself based on your criteria.
Sorting with Multiple Levels
Sometimes, a single column isn't enough to organize your data effectively. You might want to sort by Sales figures, but if two items have the same sales amount, you want them sorted alphabetically by Name. Excel handles this automatically with multiple levels.
- Open the Sort dialog box. Follow Steps 1 through 3 above to open the Sort menu.
- Add a level. Look for a button at the bottom of the dialog box labeled Add Level. Click this button. You will now see a new row of dropdown menus labeled Then by.
- Configure the second level. Select the appropriate header from the Then by dropdown. For the example above, you would choose "Name". Set the Sort On to Values and the Order to A to Z.
- Add more levels if necessary. If you have more than two criteria (for example, sorting by Sales, then by Name, and finally by Region), simply click Add Level again to create a third row.
- Apply the sort. Click OK to apply the multi-level sort. Excel will first sort by the primary criteria, and for any ties, it will immediately apply the secondary criteria, and so on.
Sorting Dates and Times
Sorting dates and times in Excel works differently than sorting text. Excel stores dates as serial numbers, allowing it to calculate the difference between two dates. To sort dates correctly, ensure the cells are formatted as a Date type.
- Select the date column. Highlight the column containing your dates.
- Change the format (if necessary). Right-click on the selected cells and choose Format Cells. Go to the Number tab and select Date from the list on the left. Ensure the correct regional date format is selected and click OK.
- Sort. Follow the standard sorting steps. You can choose Newest to Oldest or Oldest to Newest from the Order dropdown, depending on your preference.
Common Mistakes
- Not selecting the headers. If you forget to include the header row in your selection, Excel will try to sort the headers along with the data, which will likely result in an error or a messy spreadsheet where your data labels are mixed with your values.
- Sorting only a single column. If you select just one column of data without its corresponding row headers, Excel will attempt to sort that column independently. The data in the other columns will remain in their original positions, effectively breaking your dataset.
- Sorting unclean data. If your data contains blank rows or merged cells, the sort may behave unpredictably. Blank rows can be skipped or treated as a specific value, and merged cells can cause alignment issues. It is best practice to clean your data before sorting.
- Ignoring text formats. Sometimes, numbers are stored as text (e.g., "100" instead of 100). When you sort these, they will be treated as text, meaning "100" will come before "20" because of the way text is sorted character by character. Use the Text to Columns feature to convert text numbers to actual numbers before sorting.
Tips
- Use the Filter button. The Filter button (the funnel icon) is often a faster way to sort data. Clicking it adds dropdown arrows to your headers. You can click these arrows to sort A to Z or Z to A without opening the Sort dialog box. This is excellent for quick, one-time sorts.
- Keyboard shortcuts. You can sort a selected range with a single keyboard shortcut. Highlight your data, press Alt + A + S to open the Sort dialog box, and then press Enter to apply the default sort (A to Z on the first column). This is much faster for power users.
- Protect your original data. Before performing a major sort on a critical dataset, it is wise to make a copy of the sheet. You can do this by right-clicking the sheet tab at the bottom of the window and selecting Move or Copy. Check the Create a copy box. This way, if you make a mistake, you can simply delete the copy and start over.
- Custom Sort. For very specific requirements, such as sorting by a custom list of states or priority levels (High, Medium, Low), use the Custom List option in the Sort dialog box. This allows you to define your own sorting order that Excel will recognize.
Troubleshooting
If your spreadsheet does not sort as expected, the issue is often related to how the data is formatted or structured.
Sort Options are Greyed Out
If you try to sort but the Sort button or the options within the Sort dialog box are greyed out (unavailable), it is usually because you have not selected a range of data. Ensure that you have clicked and dragged to highlight a specific block of cells, including the headers, before clicking the Sort button.
Excel Sorts by Row Instead of Column
By default, Excel sorts by column. However, if your data is formatted as a Table (inserted via Insert > Table), the sort options can sometimes behave differently depending on the version of Excel. If you are sorting a Table and it sorts by row, check the Sort On dropdown in the Sort dialog box and ensure it is set to Values. If it is set to Cell Color or Font Color, the sort direction can feel reversed or confusing.
Data is Sorted Incorrectly (Text vs Numbers)
If you are trying to sort numbers and the order looks wrong (e.g., 100 comes before 2), the numbers are likely stored as text. You cannot fix formatting issues with a simple sort. You must convert the data. Select the column, go to the Data tab, and click Text to Columns. Choose Finish on the first two dialog screens without changing any settings. This will trigger Excel to recognize the numbers as numeric values, allowing standard sorting to work correctly.
Sorting Only Part of the List
If you select a range that is not a full rectangle (e.g., you select columns A, B, and C, but there is a gap in column D), Excel may sort only the columns you selected and leave the rest of the data untouched. Always ensure your selection forms a complete block of contiguous cells for the sort to work on the entire dataset.
Frequently Asked Questions
Can I undo a sort?
Yes. If you make a mistake, you can press Ctrl + Z immediately after sorting to reverse the action and return your data to its original order.
Does sorting remove blank rows?
No. Standard sorting in Excel preserves the structure of your data. Blank rows will remain in place, though they may move to the top or bottom depending on your sort order settings.
How do I sort by color?
To sort by cell color or font color, select the range, click the Sort button, and in the Sort On dropdown, choose Cell Color or Font Color. You can then choose which specific color to sort by.
Why does my data look like #######?
The ####### error occurs when a column is too narrow to display the full number. This is not a formatting error; the data is still there. Simply click and drag the right edge of the column header to widen the column until the numbers become visible.
Can I sort a PivotTable?
Yes, but the process is different from sorting a standard range. In a PivotTable, you can right-click any value in the table and select Sort to rearrange the rows or columns without affecting the underlying data source.