Blog
How to Sort in Excel: Multiple Columns, Custom Order, Fixes
Sorting in Excel rearranges the rows of a table by the values in one or more columns. It takes one click, and one wrong click can scatter student names and scores across different rows. Once the file is saved, there is no way back to the original order, so a scrambled gradebook means exporting it again and re-entering everything you typed since. Here is how to sort by one column, by several, in a custom order, with formulas, and what to check when a sort comes out wrong.
Sort by one column

- Click one cell in the column you want to sort by. You do not need to select the column.
- Choose Home > Editing > Sort & Filter > Sort A to Z (or Smallest to Largest, Oldest to Newest, depending on the data). The same buttons sit in the Sort & Filter group on the Data tab.
With a single cell selected, Excel detects the surrounding table and moves whole rows together. Trouble starts when you select just one column. Excel then shows a Sort Warning with two choices: Expand the selection moves the neighboring columns too, while Continue with the current selection sorts that column alone and breaks every row. Pick Expand almost every time, and if you already sorted the wrong way, press Ctrl+Z before saving.
In an ascending sort, Excel places numbers first, then text, then logical values (FALSE before TRUE), then errors. Blank cells always go to the bottom, ascending or descending. That is why numbers bunch at the top of a column that mixes numbers and text.
On a filtered table, the header arrows sort directly. Rows you hid manually are a different story: hidden rows are not moved by a sort, so unhide all rows and columns before sorting.
Sort by multiple columns with the Sort dialog
When you need a second rule, such as class period first and then last name within each period, use the Sort dialog.
- Click inside the table and choose Data > Sort.
- Keep My data has headers checked if row 1 holds column names.
- In the Sort by row, choose the first column, Sort On (Cell Values) and Order.
- Click Add Level to create a Then by row for the next column. Repeat as needed.
The top row wins. Rows are sorted by the second level only where the first level ties. Use the arrow buttons to change priority, and Copy Level to duplicate a level with its settings. You can add up to 64 levels.
The Microsoft Learn reference for SortFields.Add defines each sort level by the same parts you see in the dialog: the key range, which cell property to sort on, the order, an optional custom order and how text is treated. The Sort On box offers Cell Values, Cell Color, Font Color and Conditional Formatting Icon, the four options listed in the XlSortOn reference. To bring rows highlighted red by a failing-grade rule to the top, sort on Cell Color and put red On Top.
The Order box also offers Custom List. Type your own sequence, such as "Fall, Winter, Spring" for benchmark testing windows, and the column sorts in that order instead of alphabetically. Days of the week and month names are built in. The Options button adds Case sensitive and a left-to-right orientation, which sorts columns instead of rows, handy for reordering month columns.
Sort with formulas: SORT and SORTBY
Microsoft 365 and Excel 2021 or later include sort functions:
=SORT(A2:E321,3,1)
=SORTBY(A2:E321,B2:B321,1,D2:D321,-1)
The first spills A2:E321 sorted by its third column, ascending. The second sorts by column B ascending and then column D descending. The source stays in its original order and the result updates when the source changes, which suits a sheet where one person enters data and others read a sorted view. Keep the spill area clear or you get #SPILL!. Files with these functions show #NAME? in Excel 2019 and earlier.
Five reasons a sort goes wrong
1. Numbers stored as text sort character by character: 1, 10, 2, 20. A green triangle in the cell corner gives it away.

Select the range and choose Convert to Number from the warning icon, or select the column and run Data > Text to Columns > Finish. Codes with leading zeros, such as 00123, should stay text; make them all the same length instead. If you cannot change the data, sort through the Sort dialog. When numbers stored as text are present, Excel asks whether to sort anything that looks like a number as a number, the option the XlSortDataOption reference calls sorting text as numbers.
2. Dates stored as text sort as strings, so 2024/01/05 and 2023/12/20 interleave.

Select the date column, open Data > Text to Columns, choose Date in step 3 with the matching order (YMD, MDY) and click Finish.
3. Leading or trailing spaces send " Eco Mug" to the top of an A to Z list.

Put =TRIM(C2) in a helper column, fill down, copy the results, paste them back as values and delete the helper.
4. Merged cells stop the sort with a message that merged cells must all be the same size. Select the table, click Home > Merge & Center to unmerge, fill the blanks and sort again.
5. Blank rows or columns inside the data make Excel treat only the block above the gap as the table. Delete the blank rows or select the full range yourself. Converting the range to a table with Ctrl+T avoids the problem.
👉 Find Duplicates in Excel: Highlight, Count and Compare Lists
Worked example: a weekly reading score report
Every Wednesday an elementary reading specialist prepares the score report for Thursday's intervention meeting. The export from the school's reading assessment tool has grade, homeroom teacher, student name, words correct per minute, the score from the previous check and the date assessed, 540 rows in all. The team reads it "by grade, lowest score first."
Her first sort looked wrong in two ways. Some 3rd graders sat at the very top, and scores ran 5, 50, 6, 60. The first was a leading space in the grade name on rows pasted from another report; the second was a block of scores stored as text. A TRIM helper column fixed the grade names, and Text to Columns fixed the scores.
Grades had to appear in school order, Kindergarten, 1st, 2nd, 3rd, 4th, 5th. An A to Z sort puts Kindergarten last, so she added that custom list in the Sort dialog. A conditional format already filled rows red where the score had dropped since the previous check. Her levels became grade (custom list), then cell color with red on top, then score ascending. Color comes before score because a student who fell from 92 to 71 words per minute can still sit in the middle of the grade, and a score-only sort would bury the drop.
Before sorting she added a Row column numbered 1 to 540, so sorting by it restores the export's original order at any time. The team now reads the first few lines under each grade. Next week the custom list is still there, so after cleaning spaces and text numbers she reapplies the same three levels in seconds.
Version and sharing differences
Excel 2007 raised the limit to 64 sort levels; Excel 2003 allowed three. SORT and SORTBY exist only in Microsoft 365 and Excel 2021 or later, so sort with the dialog when you send a file to a colleague on an older version. In a workbook shared on OneDrive or SharePoint, sorting changes the order for everyone who has it open. In Microsoft 365, View > Sheet View > New creates a personal view where your sort leaves other people's screens alone.
FAQ
Q. Can I get the original order back after sorting?
Before saving, Ctrl+Z undoes it. After saving, only a row-number column you added beforehand can restore the order.
Q. My header row was sorted into the data.
My data has headers was unchecked. Undo, check the option and sort again. Bold headers or a formatted table help Excel recognize them.
Q. Can Excel sort case-sensitively?
Yes. In the Sort dialog, click Options and check Case sensitive. Lowercase then sorts before uppercase in ascending order.
Q. Values in a formula column changed after sorting.
The formulas referred to cells in other rows with relative references. Rewrite them to refer only to their own row, or copy the column and paste it as values before sorting.
Sort a messy score export with inline AI
inline AI opens the export on your PC, and when you say "Kindergarten through 5th grade order, dropped scores first, then lowest score," it cleans the leading spaces and text numbers before applying the sort. Add "number the rows first" to the request and the original order stays one sort away.
Gradebooks and spreadsheets, finished by inline AI in the file itself.
Ask in one sentence for roll-ups, trackers and the cleanup you repeat every week. Your files never leave your computer.





