How to Sort Data in Excel
How to Sort Data in Excel
Answer: Use Excel's built-in Sort commands. To do a quick sort, select a cell in the column you want ordered and use the A-Z or Z-A buttons on the Data tab; for precise control open Data > Sort and choose columns, order, and Add Level for multi-column sorts. For custom orders or color/icon sorts use the Custom Sort options in that dialog.
Quick single-column sorts
When you only need to order rows by one column (name, date, size, score), Excel offers two fast controls that preserve entire rows: the A to Z and Z to A buttons. These perform ascending or descending sorts and keep records intact so other columns follow the sorted key.
- Select any cell in the column you want to sort by.
- Click the A to Z button for ascending order or Z to A for descending order on the Data tab.
- Confirm that Excel expands the selection if it prompts; choose to sort the entire table so rows stay together.
- If the column contains numbers stored as text, fix them first to avoid unexpected order (see troubleshooting below and Fixing Numbers Stored as Text in Excel).
Multi-column sorting (stable, layered sorts)
Multi-column sorting applies a primary key, then a secondary key, then a tertiary, and so on. Use it when you need predictable grouping—examples include sorting by region then by salesperson, or by department then by hire date.
When to use multi-column sorting
- You need deterministic order inside groups (for example, state then city then street).
- There are duplicate values in the first column and you want a secondary column to break ties.
- You want a hierarchical report-ready sort rather than multiple single sorts.
Step-by-step multi-column example
Follow this process to sort by three fields in a sample table:
- Select a cell anywhere in the table and open Data > Sort. Do not select only one column unless prompted to expand the selection.
- In the Sort dialog, set the top level: choose the first column (primary key) and set Order (A to Z, smallest to largest, newest to oldest).
- Click Add Level. For Level 2 choose the second column (secondary key) and its Order.
- Click Add Level again for the tertiary key and set the Order.
- Use the Move Up / Move Down buttons to change priority and click OK to apply the layered sort.
Custom sort orders, color and icon sorts
Standard sorts handle alphabetical and numeric order, but you can also define a custom sequence or sort by cell/ font color and conditional formatting icons. These are useful when the natural order isn't what your report needs.
Custom list (nonstandard order)
- Open Data > Sort and choose the column to sort.
- Set Order to Custom List and either pick an existing list (Weeks, Months) or create a new one with your sequence (High, Medium, Low).
- Confirm the custom list and click OK; rows will follow that exact sequence.
Sort by color or icon
- Open Data > Sort and pick the column containing color or icons.
- In the Order dropdown choose Sort On: Cell Color, Font Color, or Cell Icon.
- Select the specific color or icon and choose whether it goes on top or bottom. Add levels to handle multiple colors or icons.
Common problems and troubleshooting
Sorting can look wrong when underlying data is inconsistent, headers are included or excluded improperly, or Excel misidentifies data types. Check these frequent issues first.
- Header row treated as data: If your header moves into the data, ensure the range is a proper table or check the 'My data has headers' box in the Sort dialog.
- Mixed data types: Text mixed with numbers sorts as text. Use the procedures in Fixing Numbers Stored as Text in Excel to normalize types.
- Hidden rows or filters: Active filters or hidden rows can make sorts seem incomplete. Clear filters first using the Data tab or use How to Filter Data in Excel to inspect what is hidden.
- Unexpected duplicates: Duplicates may be present because of trailing spaces or invisible characters—run a cleanup routine or see How to Clean Data in Excel.
- Rows moved but formulas broken: If formulas use absolute references rather than structured references, you can break calculations. Convert ranges to Excel tables to keep structured references stable.
Quick checklist before sorting
- Confirm the selection will include all columns for each record.
- Verify the header row is set correctly or convert the range to a table.
- Standardize data types in the key columns (numbers, dates, text).
- Remove leading/trailing spaces or nonprinting characters; consider running a cleanup pass described in How to Clean Data in Excel.
Worked example: sorting a student roster
Imagine a roster with columns: Class, Last Name, First Name, Grade. You want rows grouped by Class, then sorted by Last Name A to Z, then Grade descending.
- Click any cell in the roster and open Data > Sort.
- Set the first level: Column = Class, Order = A to Z.
- Add Level: Column = Last Name, Order = A to Z.
- Add Level: Column = Grade, Order = Largest to Smallest (descending).
- Click OK — result: all students sorted by class, within class alphabetically by last name, and ties ordered by grade.
When sorting fails: a short troubleshooting flow
- Step 1: Did the header move? If yes, re-open Sort and check 'My data has headers'.
- Step 2: Are values out of order because they are text? Use Fixing Numbers Stored as Text in Excel.
- Step 3: Do duplicates or blank rows persist? Run duplicate removal or cleaning: How to Remove Duplicates in Excel and How to Clean Data in Excel.
Closing: keep sorts repeatable and auditable
Sorting is a basic operation but small data inconsistencies make results unpredictable. Convert ranges to Excel tables when appropriate, document the sort order you used, and keep a copy of the unsorted sheet if you may need to revert. For recurring reports, consider recording a short macro or using Power Query to apply a consistent, auditable sort and cleanup routine.
If you need focused help on cleaning or preparing your data before sorting, see How to Clean Data in Excel, How to Remove Duplicates in Excel, Fixing Numbers Stored as Text in Excel, and How to Filter Data in Excel.