Excel Sort Not Working? Causes and Quick Fixes
By ExcelReady TeamUpdated 6 min read
The short answer
When Excel sort is not working, the data is usually the problem, not the sort. Numbers or dates stored as text sort in the wrong order, leading spaces push rows to the top, merged cells block the sort, and blank rows stop Excel from selecting the whole table. Clean the column with TRIM and VALUE, unmerge cells, then sort again.
Key takeaways
- Numbers stored as text sort like words, so 120 comes before 45. Convert them with VALUE or Convert to Number.
- A leading space sorts before any letter or digit. Remove it with TRIM.
- Select one cell in the table, not one column, or the rows get scrambled.
- Merged cells must all be the same size before Excel will sort; usually it's easier to unmerge them.
- SORTBY with VALUE and TRIM can sort messy data correctly without changing the original.
On this page+
- Quick checklist: why is Excel sort not working?
- Numbers and dates sort in the wrong order
- Spaces and hidden characters push rows to the top
- Rows get mixed up or only part of the data sorts
- Sort is greyed out or shows a merged cells error
- Months or sizes sort alphabetically
- Sort messy data with a formula instead
- Practise it
When Excel sort is not working, the sort itself is almost never broken. The problem is in the data: numbers stored as text, spaces you can't see, merged cells, or a blank row that cuts the table in two. This guide gives a quick checklist, then the fix for each cause, so you can sort with confidence in a report or a job test.
Quick checklist: why is Excel sort not working?#
Match what you see to the likely cause, then jump to the fix:
| What you see | Likely cause | Quick fix |
|---|---|---|
| 120 sorts before 45 | Numbers stored as text | Convert with VALUE or Convert to Number |
| A few rows stay at the top or bottom | Leading spaces or hidden characters | Clean with TRIM (and CLEAN) |
| Dates sort by day or month name | Dates stored as text | Convert with DATEVALUE |
| Data in other columns no longer matches | Only one column was sorted | Undo, select one cell, sort again |
| Only part of the table sorts | Blank row or column in the data | Remove the blanks or select the full range |
| Header row ends up in the middle | Excel didn't detect the header | Tick My data has headers |
| Error about merged cells | Merged cells of different sizes | Unmerge the cells |
| Months sort April, August, December | Alphabetical sort on text | Use a custom list |
Numbers and dates sort in the wrong order#
Numbers stored as text sort like words: character by character, from the left. So "120" comes before "45", because 1 comes before 4. Text numbers usually sit on the left of the cell and may show a small green triangle in the corner.
To fix them, select the column, click the warning icon and choose Convert to Number. Or use a helper column with =VALUE(B2) and sort by that. Excel's Sort dialog may also warn that a column contains numbers formatted as text and offer to sort anything that looks like a number as a number. Converting the data is the safer long-term fix. The VALUE function guide and the article on numbers stored as text cover every method.
Dates have the same problem. A text date like "05/10/2026" sorts by its first characters, so all the 01s come first, whatever the month or year. Convert them with DATEVALUE or Text to Columns; the guide to converting text to dates walks through both.
Spaces and hidden characters push rows to the top#
A space sorts before any letter or digit. So " Zara", with a leading space, lands above "Adam" in an A to Z sort, and it looks like the sort failed. Data pasted from websites, PDFs and other systems often brings these spaces with it.
Clean the column in a helper column:
=TRIM(A2)TRIM removes spaces at the start and end and turns double spaces into single ones. For line breaks and other non-printing characters, use =TRIM(CLEAN(A2)). Then paste the results as values over the original and sort again. Web data sometimes contains a non-breaking space (character 160) that TRIM can't remove; replace it first with SUBSTITUTE(A2,CHAR(160)," "). The TRIM function guide has more examples.
Rows get mixed up or only part of the data sorts#
If you select a single column and sort it, only that column moves. Names end up next to the wrong salaries, and the damage is easy to miss. Excel usually shows a Sort Warning asking whether to expand the selection. Always choose Expand the selection. If you've already sorted the wrong way, undo straight away with Ctrl+Z (Mac: ⌘Z).
The safest habit is to click one cell inside the table and then sort. Excel selects the whole block of data around it. That block stops at the first completely blank row or column, so a blank row in the middle means only the top half gets sorted. Delete the blank rows, or select the full range yourself before sorting.
Two more checks:
- Header row sorted into the data. In Data > Sort, tick My data has headers.
- Formulas that change after sorting. Formulas that point at cells in other rows, or at other sheets, can give new answers once the rows move. Paste them as values before sorting if the results must stay put.
Sort is greyed out or shows a merged cells error#
If the Sort buttons are greyed out, check three things. You may still be editing a cell (press Esc). The sheet may be protected (Review > Unprotect Sheet). Or several sheets may be grouped, which shows "Group" in the title bar (right-click a sheet tab > Ungroup Sheets).
If Excel complains that merged cells must all be the same size, the range has merged cells of different sizes. Select the range, click Home > Merge & Center to unmerge, and fill in any blanks. If you only wanted a centred title, use Center Across Selection instead. The article on Merge and Center explains why merged cells cause so much trouble.
Months or sizes sort alphabetically#
When a column holds month names as text, A to Z gives April, August, December. That's correct alphabetical order, just not what you want. Real dates formatted to show the month sort correctly. For text such as Small, Medium, Large, use a custom list: Data > Sort > Order > Custom List. The guide to custom sort orders shows the steps, and how to sort data in Excel covers multi-column sorts.
Sort messy data with a formula instead#
In Excel 2021 and Microsoft 365, SORT and SORTBY return a sorted copy of the data in new cells and leave the original alone. SORTBY can also clean the sort key on the fly, so messy text prices still sort correctly:
| A | B | |
|---|---|---|
| 1 | Product | Price |
| 2 | Desk lamp | " 45" |
| 3 | Office chair | "189 " |
| 4 | Monitor | " 230" |
| 5 | Keyboard | "35" |
| 6 | Webcam | "95 " |
| 7 | Headset | " 120" |
The prices are text with stray spaces. A normal Z to A sort on column B puts Webcam first, because "9" is the highest first character. This formula sorts by the real numbers instead:
=SORTBY(A2:A7,VALUE(TRIM(B2:B7)),-1)TRIM removes the spaces, VALUE turns the text into numbers, and -1 means largest first. The result spills down: Monitor, Office chair, Headset, Webcam, Desk lamp, Keyboard. The SORT function guide covers the simpler SORT, which sorts by a column of the same range.
Practise it#
Sorting and cleaning go together in almost every data task, and job tests often hide text numbers or extra spaces in the data on purpose. Practise the SORT function in a live spreadsheet: you type the formula and it checks it instantly. Then clean data in the cleaning text lesson and fix text numbers in the text and VALUE lesson, or try the exercise on this page first.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
The prices in B2:B7 are text with stray spaces, so a normal sort puts them in the wrong order. In D2, use SORTBY to list the products (A2:A7) by their real price, highest first: sort by VALUE(TRIM(B2:B7)) with -1.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Price | By price | |||
| 2 | |||||
| 3 | |||||
| 4 | |||||
| 5 | |||||
| 6 | |||||
| 7 | |||||
| 8 | |||||
| 9 | |||||
| 10 |
Tip: SORTBY(what to return, what to sort by, -1). The sort-by part is VALUE(TRIM(B2:B7)).
Practise this in a lesson
Frequently asked questions
Why is Excel not sorting my numbers correctly?
The numbers are probably stored as text, so Excel sorts them character by character: 120 comes before 45 because 1 comes before 4. Convert the column to real numbers with VALUE, or select it and use the Convert to Number option, then sort again.
Why is the Sort button greyed out in Excel?
The sheet may be protected, you may be editing a cell, or several sheets may be grouped. Press Esc to leave the cell, unprotect the sheet in the Review tab, or right-click a sheet tab and choose Ungroup Sheets.
Why does Excel say all merged cells need to be the same size?
Your range contains merged cells of different sizes, and Excel can't move them row by row. Select the range, click Merge and Center to unmerge, and use Center Across Selection if you only wanted the look.
Why did sorting mix up my data?
Only one column was sorted, so its values moved while the other columns stayed put. Undo straight away with Ctrl+Z (Mac: Command+Z). Next time click one cell in the table, or choose Expand the selection when Excel asks.
Why are my dates not sorting in date order?
Some or all of the dates are text, so they sort alphabetically. Convert them to real dates with DATEVALUE or Text to Columns, then sort oldest to newest.