Excel guide · 5 min read
Excel sort not working: 7 fixes
Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Rep | Region | Invoice | Amount |
| 2 | Dana Price | West | INV-2041 | 1850 |
| 3 | Tom Reyes | East | INV-2042 | 920 |
| 4 | Alex Chen | West | INV-2043 | 2400 |
| 5 | Sara Ortiz | North | INV-2044 | 640 |
| 6 | Ben Walsh | East | INV-2045 | 3100 |
| 7 | Kim Lee | North | INV-2046 | 1275 |
| 8 | Maria Gomez | West | INV-2047 | 510 |
| 9 | Ravi Shah | East | INV-2048 | 1460 |
Download this sheet as an Excel practice file (.xlsx)
1. The header row gets sorted into the data
Excel guesses whether row 1 is a header. If your headers look like data (for example a column of numbers whose header is a year like 2026), the guess goes wrong and "Amount" ends up somewhere in the middle.
Use the full Sort dialog instead of the A-Z button. It has a My data has headers box, and the Sort by list then shows your column names, which is also how you can tell Excel read them correctly.
- Click any cell in the list.
- Go to Data > Sort.
- Tick My data has headers (top right).
- Choose the column and order, then OK.
2. Only one column sorted, and the rows no longer match
If you select just the Amount column and sort, Excel shows a Sort Warning: Expand the selection, or Continue with the current selection. Continue sorts only that column. The amounts move, the reps and invoice numbers stay put, and every row is now wrong.
If you just did it, press Ctrl+Z straight away. If you've saved and closed since, the original order is gone, which is why it's worth adding a row number column (1, 2, 3...) to any list before sorting: sort by it to get back to the start.
To avoid the warning, click a single cell in the column instead of selecting the column. Excel then sorts the whole list by that column.
- Press Ctrl+Z to undo the one-column sort.
- Click one cell in the column you want to sort by.
- Go to Data > Sort A to Z (or Z to A). If the warning appears, choose Expand the selection.
3. Some numbers sort in the wrong place
Here three amounts (920, 3100 and 1460) came in from an export as text. Excel sorts numbers and text separately: smallest to largest puts all the real numbers first, then the text ones after them. So 920 lands below 2400.
Count them: =COUNTA(D2:D9)-COUNT(D2:D9) returns how many cells hold something that isn't a number. Text numbers usually sit on the left of the cell and show a small green triangle. Convert them with Data > Text to Columns > Finish on the column, or the warning icon's Convert to Number, then sort again.
Result: 3
3: three of the eight amounts are stored as text.
4. A name sorts to the top for no reason
" Tom Reyes" was typed with a space in front. In an A to Z sort, a leading space comes before every letter, so he sorts above Alex Chen. Non-breaking spaces from web pages and stray characters from exports do the same.
=SORT(TRIM(A2:A9)) in Excel 365 shows the order you'd get with the spaces removed. To fix the data, put =TRIM(A2) in a spare column, copy it down, paste it back over the names as values, and sort again. The remove spaces guide covers non-breaking spaces, which TRIM doesn't remove.
Result: spills 8 rows × 1 column
| Alex Chen |
| Ben Walsh |
| Dana Price |
| Kim Lee |
| Maria Gomez |
| Ravi Shah |
| Sara Ortiz |
| Tom Reyes |
Spills the eight names A to Z, with Tom Reyes last, after Sara Ortiz, where he belongs.
5. "To do this, all the merged cells need to be the same size"
Excel can't sort a range where some cells are merged and others aren't, or where merged areas differ in size. A merged title above the list is fine as long as it isn't inside the range you sort.
Select the list, go to Home > Merge & Center > Unmerge Cells, and fill any gaps the unmerge leaves. If you merged a heading only to centre it, use Center Across Selection (Ctrl+1 > Alignment) instead.
6. Half the list doesn't move
When you click one cell and sort, Excel sorts the current region: the block of cells around it up to the first fully blank row and column. A blank row in the middle means only the part above (or below) it gets sorted. A blank column means the columns on the far side are left behind and their rows no longer match.
Delete blank rows and columns inside the list, or select the whole list yourself before sorting. Better still, turn it into a table with Ctrl+T: the table's own sort always sorts the whole table, blank rows and all.
7. The order changes after you sort, or formulas break
Formulas with RAND, RANDBETWEEN, TODAY or NOW recalculate every time Excel recalculates, and sorting is one of those times. A list sorted by a RAND column is shuffled again straight after. Copy the column and paste it as values before you sort by it.
Formulas that point at a cell in another row can also show different numbers after a sort, because the formula moves with its row but its reference may not point where you expect. Formulas that only use their own row (=C2*D2) or locked cells ($H$1) are safe. If in doubt, paste values on a copy of the sheet and sort that.
If you want the data to stay put and just see it in order, use a formula: =SORT(A2:D9,4,-1) spills the list sorted by the Amount column, largest first, and updates when the data changes. Convert the text amounts first: SORT orders them the same way the Sort button does, so in a largest-first sort the three text amounts come out on top.
Common mistakes
Selecting one column before sorting
Click a single cell, or choose Expand the selection when Excel warns you.
Sorting without a way back
Add a row number column first, so sorting by it restores the original order.
Converting text numbers after sorting
Convert first, then sort. Otherwise the text ones end up in their own block.
Leaving blank rows inside the list
Delete them, select the whole list, or use a table so the sort covers everything.
FAQ
Why is Excel not sorting my numbers correctly?
Some of them are stored as text. Excel sorts real numbers first and text after them. Convert the column with Data > Text to Columns > Finish and sort again.
Why does Excel only sort one column?
You selected only that column and chose Continue with the current selection. Undo with Ctrl+Z, click a single cell instead, and sort; or choose Expand the selection.
Why is sort greyed out in Excel?
Usually the sheet is protected without sorting allowed, several sheets are grouped ([Group] in the title bar), or you're still editing a cell. Unprotect or ungroup the sheets, or press Enter or Esc first.
How do I undo a sort in Excel?
Press Ctrl+Z straight away. Once the file is saved and closed, the original order can only be restored if you had a row number column to sort by.
Functions used
Related guides
- Excel dates not sorting correctly: how to fix it
- How to convert numbers stored as text in Excel
- How to sort by multiple columns in Excel
- How to sort data with a formula in Excel
- Excel filter not working: 7 fixes
- #SPILL! error in Excel
- Pivot table not working: 7 fixes
Updated