Excel Sorting: How to Sort Data Without Breaking It
In this article
Sorting in Excel rearranges your rows in a chosen order based on one or more columns, and it takes about three clicks: select a cell inside your data, open the Home tab, click Sort & Filter, and choose Sort A to Z, Sort Z to A or Custom Sort. The catch is that Excel's quick buttons only keep whole rows together when it can tell where your table ends. The steps below keep your records intact, add multi-level sorts, and cover the fixes when columns end up mismatched.
What You'll Need
- Excel for Windows, Mac or the web (the ribbon layout is nearly identical; labels can differ slightly by version, device or region).
- Data arranged in a proper table: one header row, one record per row, and no blank rows or columns inside the block.
- Backup of anything you cannot easily rebuild, since sorting is undoable with Ctrl+Z but harder to reverse after saving and closing.
Step-by-Step
- Make a backup first. Save a copy of the workbook or the sheet before heavy sorting. Ctrl+Z (Cmd+Z on Mac) undoes a sort while the file is still open, but once you save, close and reopen, that history is gone.
- Clean the block. Remove blank rows and blank columns inside your data. A blank column makes Excel treat the data on either side as two separate blocks, so a sort only moves half of each record.
- Give every column a unique header. Two columns both called "Date" or a missing header in column A forces Excel to guess whether row 1 is data or titles. Unique, non-blank header names remove the guesswork.
- Convert the range to a table (recommended). Click any cell in the data, then press Ctrl+T (Cmd+T on Mac), or use Insert > Table, and confirm the "My table has headers" box. Tables expand automatically when you add rows and keep the whole record together, which prevents most sorting accidents.
- Select a single cell inside the data. Do not select just one column unless you deliberately want that column sorted independently. With one cell selected, Excel treats the surrounding block as the target.
- Use the quick sort buttons. On the Home tab, open Sort & Filter and choose Sort A to Z or Sort Z to A. Numbers sort smallest to largest, text sorts alphabetically, and dates sort chronologically from oldest to newest.
- Run a custom multi-level sort. Go to Data > Sort. In the dialog, tick "My data has headers" so the header names appear in the lists instead of Column A, Column B and so on. Set the first Sort by column, choose Sort On (values, cell colour or font colour) and the Order, then click Add Level for a second and third key. Example: sort by Department A to Z, then by Hire Date oldest to newest, then by Last Name A to Z.
- Sort by custom or manual order. In the same dialog, choose Custom List under Order to sort months or weekdays in calendar order rather than alphabetically, or pick a list you have defined.
- Sort by colour or icon. Choose the column, set Sort On to Cell Color, Font Color or Conditional Formatting Icon, then pick which colour goes on top. This is useful for flagging overdue tasks or low stock first.
- Check the result before saving. Look at the first and last rows and confirm each row still belongs to one record: a name still lines up with the right phone number and date. If row integrity is wrong, press Ctrl+Z immediately.
- Sort only part of the sheet if needed. Select the whole block you want to reorder, then use Data > Sort and tick "My data has headers". Never sort a block that sits beside unrelated columns without selecting it first.
- Save and, if useful, add filters. Turn on Data > Filter to sort and hide items interactively. A filter keeps the sort order you apply from its own drop-down arrows.
Common Mistakes
- Sorting one column and destroying rows. This happens when Excel does not detect a contiguous block or the header box is left unticked. The symptom is data that no longer matches across columns.
- Leaving "My data has headers" unticked. Excel then sorts the header text into the data, so "Customer" ends up between two surnames.
- Numbers stored as text. Left-aligned numbers with a green warning triangle sort as text, so 10 can come before 2. Use Data > Text to Columns or convert the column to Number first.
- Leading spaces and inconsistent capitalisation. Text sorts by character code, and stray spaces push entries to unexpected positions. TRIM and PROPER in a helper column fix this, or use the trim option in Power Query.
- Mixed date formats. Dates entered as text do not sort chronologically. Standardise the column with Date > Text to Columns before sorting.
- Sorting a filtered list. Sort applies to visible rows only in some versions and to the whole list in others. Clear filters first if you want a full sort.
- Formulas pointing at fixed cells. A sort moves values, not references. Use structured references in tables ($ syntax) so formulas follow rows rather than positions.
Tips
- Add a numbered "Original order" column before any big sort so you can restore the starting sequence by sorting on it.
- Name columns with plain, unique words and avoid merged header cells; merged cells break sorting and filtering.
- Use a table (Ctrl+T) rather than a plain range wherever the data will grow.
- For repeatable multi-level sorts, record the sequence with a macro or recreate it in Power Query so the same order runs every time.
- When sorting by an ID or account number, make sure that column is stored as text if leading zeros matter; otherwise Excel drops them.
- Sort before you build pivot tables or charts so the source is in a predictable order.
Troubleshooting
- Rows no longer match across columns. Undo with Ctrl+Z at once. Then rebuild by adding a backup copy, confirm the header box is ticked and the block has no blank rows or columns, and sort again.
- The header row got sorted into the data. Undo, then retick "My data has headers" in Data > Sort, or insert a genuine header row.
- Numbers sort oddly (1, 10, 100, 2). The column is text. Select it, use Data > Text to Columns, finish without changing anything to refresh the type, then set the format to Number and sort again.
- Dates sort alphabetically. The dates are text. Convert them with Text to Columns and choose a correct date format.
- Excel sorts only part of the list. There is a blank row or column splitting the range. Delete the gap, or select the full block deliberately before sorting.
- The sort does not move cells you expected. You may have selected a single column, or the data is in separate ranges. Select one cell inside a contiguous table instead.
- Locked or protected cells. On a protected sheet, sorting is disabled. Unprotect the sheet under Review > Unprotect Sheet if you have the password, or ask the workbook owner.
- If that did not work, rebuild the sheet from the backup, verify header names, remove merged cells and stray spaces, convert the range to a table and sort with Data > Sort from a single selected cell.
Frequently Asked Questions
Does sorting change formulas?
Cell references stay pointing at the same positions, so relative references can return different values after a sort. Structured table references avoid this because they follow the row.
Can I sort by more than one column?
Yes. Use Data > Sort and click Add Level for each additional key; up to 64 levels are available in a custom sort.
How do I undo a sort?
Press Ctrl+Z (Cmd+Z on Mac) while the workbook is open. If you saved and closed it, restore the backup or an earlier saved version from OneDrive or your backup drive.
Can I sort a column without moving the rest of the row?
Yes, but only deliberately: select just that column and sort. Treat it as a destructive edit, because the records no longer align.
Why does my sort ignore capital letters?
Excel sorts text case-insensitively by default. For case-sensitive ordering, use the Options button in the Sort dialog and tick case sensitivity.
Does sorting in Excel Online work the same?
The web version supports basic sorting and filtering in a table or range, but some options, such as sorting by cell colour, may not be available there. Do complicated sorts in the desktop app.