Excel Sort Command: How to Organize Your Data
In this article
The sort command in Excel allows you to reorganize your data alphabetically, numerically, or by date, making it easier to analyze patterns and find specific entries. To sort quickly, select a cell in the column you want to organize, go to the Data tab, and click either the A-Z (Ascending) or Z-A (Descending) button. This rearranges the entire row based on the values in that specific column.
What You'll Need
- A computer with Microsoft Excel installed (Windows or macOS).
- A dataset consisting of columns and rows (headers are highly recommended).
- A saved backup of your file if you are working with critical data, as sorting can occasionally displace data if not performed correctly.
Step-by-Step
Depending on your needs, you can perform a simple one-column sort or a complex multi-level sort. Note that menu labels may differ slightly depending on your version of Excel or region.
Method 1: Quick Sort (Single Column)
- Select your data: Click any single cell within the column you wish to sort. You do not need to highlight the entire column; Excel will automatically detect the surrounding data range.
- Navigate to the Data Tab: On the top ribbon, click the Data tab.
- Choose Sort Order: In the Sort & Filter group, click the A-Z button to sort in ascending order (lowest to highest, A to Z, oldest to newest) or the Z-A button for descending order (highest to lowest, Z to A, newest to oldest).
- Verify the result: Scroll through your list to ensure the rows moved together and the data remains aligned.
Method 2: Custom Sort (Multi-Level)
Use this method when you need to sort by one column and then by another (e.g., sorting by "Department" first, and then by "Last Name" within each department).
- Select the range: Click and drag to highlight the entire table you want to sort, including the header row.
- Open the Sort Dialog: Go to the Data tab and click the large Sort button. This opens a pop-up window.
- Check for Headers: In the top right corner of the dialog box, ensure the checkbox My data has headers is checked. This prevents your column titles from being sorted into the list.
- Set the First Level: Under the Column dropdown, select the primary column you want to sort by. Choose the Sort On value (usually "Cell Values") and the Order (e.g., A to Z).
- Add Additional Levels: Click the Add Level button at the top left of the dialog box. This creates a "Then by" row.
- Set the Second Level: In the new row, select the second column you wish to organize. For example, if your first level was "City," your second level might be "Customer Name."
- Apply the Sort: Click OK. Excel will now organize the data based on the hierarchy you established.
Method 3: Sorting by Color or Icon
- Highlight your data: Select the range or click a cell in the column containing the colors.
- Open Sort Dialog: Go to Data > Sort.
- Change Sort On: Instead of "Cell Values," click the Sort On dropdown and select Cell Color, Font Color, or Conditional Formatting Icon.
- Pick the Color: In the Order dropdown, select the specific color you want to appear at the top of your list.
- Finalize: Click OK.
Common Mistakes
Sorting is a powerful tool, but a few common errors can lead to corrupted data or confusing results.
Sorting only one column: One of the most dangerous mistakes is highlighting only a single column before clicking sort. If Excel asks if you want to "Expand the selection," and you choose "Continue with the current selection," Excel will only move the cells in that one column. This effectively detaches the data from the rest of the row, meaning a person's name might now be aligned with someone else's phone number. Always ensure the entire dataset is selected or that you allow Excel to expand the selection.
Hidden rows or filtered data: Sorting data that has active filters or hidden rows can sometimes lead to unexpected results. If you have a Filter applied (via the Filter button in the Data tab), the sort will only apply to the visible rows. If you intend to sort the entire master list, clear all filters first.
Mixed data types: If a column contains both numbers and text (e.g., some cells say "10" and others say "N/A"), Excel may struggle to order them logically. Numbers are typically sorted separately from text, which can create gaps or odd groupings in your list.
Blank rows in the dataset: Excel's "Auto-detect" feature for data ranges stops when it hits a completely empty row or column. If your table has a blank row in the middle, the sort command will only organize the block of data above that blank row, leaving the rest of the sheet untouched.
Tips
Use Excel Tables: Convert your data range into an official Table by pressing Ctrl + T (Windows) or Cmd + T (Mac). Tables automatically include filter dropdowns in the header row, allowing you to sort any column with just two clicks without navigating to the Data tab.
Custom Lists: Sometimes alphabetical order isn't what you need. For example, you might want to sort by "Small, Medium, Large" or "Monday, Tuesday, Wednesday." To do this, go to Data > Sort, and in the Order dropdown, select Custom List.... Here, you can create your own sequence that Excel will follow instead of the alphabet.
Sort by Helper Columns: If you have a complex sorting requirement that the standard tool cannot handle, create a "Helper Column." Use a formula to assign a number to your categories (e.g., if Category is "High", assign 1; if "Medium", assign 2) and then sort by that numerical column.
Freeze Panes: When sorting large datasets, it is easy to lose track of what your columns represent. Go to the View tab and select Freeze Panes > Freeze Top Row. This keeps your headers visible while you scroll through your newly sorted data.
Troubleshooting
If your data is not sorting as expected, try these steps in order:
Check for leading spaces: If " Apple" (with a space) is appearing before "Apple" (without a space), it is because Excel counts the space as a character. Use the TRIM function in a new column to remove extra spaces, then sort by that new column.
Verify data formatting: If dates are sorting alphabetically (e.g., January, February, March) rather than chronologically, the cells are likely formatted as "Text" instead of "Date." Select the column, go to the Home tab, and change the number format dropdown to Short Date. You may need to re-enter the dates for the change to take effect.
Remove merged cells: Excel cannot sort a range that contains merged cells. If you see an error saying "To do this, all merged cells need to be the same size," you must unmerge the cells. Select the entire sheet, go to the Home tab, and click the Merge & Center button to toggle it off for all cells.
Check for protected sheets: If the sort buttons are greyed out, the worksheet may be protected. Go to the Review tab and check if there is an Unprotect Sheet option. You will need the password if one was set by the author.
Frequently Asked Questions
Can I undo a sort?
Yes, you can undo a sort immediately after performing it by pressing Ctrl + Z (Windows) or Cmd + Z (Mac). However, if you have performed several other actions since the sort, you cannot "unsort" the data unless you have a backup or an ID column to sort back to the original order.
How do I sort by multiple columns at once?
Use the Custom Sort dialog. Go to Data > Sort, set your first criteria, click Add Level, and then set your second criteria. This allows you to nest your sorting (e.g., Sort by State, then by City).
Why are my headers being sorted into the data?
This happens when the My data has headers checkbox is unchecked in the Sort dialog. Excel treats the first row as a regular piece of data. Re-do the sort and ensure that box is checked.
Can I sort data in a different direction (horizontally)?
Yes. Go to Data > Sort, click the Options... button, select Sort left to right, and click OK. You can then choose which row to use as the sorting key.
Does sorting change the formulas in my cells?
Generally, no. If your formulas use relative references (like =A2+B2), they will move with the row and still point to the correct cells in that row. However, if your formulas refer to specific absolute cells outside the sort range, the results may change.
How do I sort numbers that are stored as text?
Excel will sort these as text (1, 10, 11, 2, 20). To fix this, select the column, click the small yellow warning icon that appears, and select Convert to Number. Then, perform the sort again.