How to Sort Columns in Excel: Every Method, Step by Step
Sorting data in Excel is fastest when you use the built-in Sort & Filter tools on the Data tab. Select any cell inside the single column you want to organize, then use the Single-Click Quick Sort method by clicking A→Z to sort smallest to largest, or Z→A to sort largest to smallest. Excel reads the whole table, reorders every row based on that column, and keeps each row’s data together. That one click handles the vast majority of everyday sorting jobs at work.

If your data sits in a clean range with a header row, Excel detects the column headers automatically and leaves them at the top. When you want a different starting point, the same commands appear on the Home tab inside the Editing group under Sort & Filter, so you can sort without leaving the formatting view. Strong sorting habits are some of the most useful Excel skills for data analysis, and they pair well with related Excel how-to guides that cover filtering, trimming blank cells, and removing duplicates.
That covers the quick answer. The sections below walk through the four primary methods: Single-Click Quick Sort, Filter Dropdown Sort, the Custom Sort Dialog Box, and Dynamic Array Formulas (SORT / SORTBY), along with sorting by multiple columns, sorting by a custom list, sorting entire columns left to right, and a sort formula and code approach for dynamic data. A troubleshooting section at the end fixes the issues that scramble rows or give unexpected results.
Method 1: One-Click Sort Buttons (Fastest)
The A→Z and Z→A buttons give the quickest path when you want to sort a single column.
- Click any cell inside the column you want to sort. Selecting only one cell works better than highlighting the entire column.
-
Go to the Data tab and find the Sort & Filter group.
- Click A→Z for ascending order or Z→A for descending order.
Excel expands the selection to cover the connected data range and sorts every row by your chosen column. Text sorts into alphabetical order, numbers sort by value, and dates sort chronologically. To quickly sort a column alphabetically, this is the fastest route, and the filter button beside it adds dropdown arrows for repeat work.

Method 2: The Sort Dialog Box for Multiple Columns
When one column is not enough, the Sort dialog box lets you sort by two or more columns at once. A common example: sort a contact list by Region first, then by Last Name inside each region.
- Click any cell in your data.
-
On the Data tab, click Sort (the larger button beside A→Z).
-
In the sort dialog, set Sort by to your primary column, choose Sort On = Cell Values, and pick the Order.
-
Click Add Level to add a second column, then a third, and so on for several columns.
- Confirm the My data has headers checkbox matches your sheet so Excel uses your column names, then click OK.
Excel applies each rule in sort order, so the first rule wins ties first and the next rule breaks remaining ties. This is how you sort based on one or more columns while keeping other columns aligned, set to ascending or descending for each level independently.

Method 3: Sort Using a Custom List
Some data follows an order that is neither alphabetic order nor numeric, such as Low, Medium, High or Mon, Tue, Wed. A custom sort built from a custom list handles this.
-
Open the Sort dialog from the Data tab.
-
Set Sort by to the column heading you want to organize.
-
Open the Order dropdown and choose Custom List.
- In the Custom Lists dialog box, create your own custom list by entering the values you want to sort by in a cell range, then import that range through Custom Lists.
- Select your custom order and click OK twice.
Excel now sorts that column by your own custom list instead of A to Z. You can manage saved lists later through File > Options > Advanced > Edit Custom Lists. Keep in mind that a custom list can be up to 255 characters, and the first character cannot begin with a number.
Method 4: Right-Click Context Menu
The right-click menu reaches the same commands without the ribbon.
- Right-click any cell in the column you want to sort.
- Hover over Sort.
- Select Sort A to Z, Sort Z to A, Sort by Selected Cell Color, or Put Selected Cell Color on Top.
This route helps when you spot the value you care about and want to sort around it in one motion.
Method 5: Keyboard Shortcuts
Keyboard sequences move faster once they become muscle memory. Click a cell in the target column first, then press each set of keys in sequence:
- Alt, A, S, A sorts the column A to Z (ascending order).
- Alt, A, S, D sorts the column Z to A (descending order).
- Alt, A, S, S opens the full Sort dialog box for custom and multi-column sorting.
These sequences walk the ribbon for you, and the on-screen letter hints appear as you press, which makes the steps easy to learn across any Excel version.
Method 6: Sort by Color, Font Color, or Icon
Conditional formatting and manual highlights become a sort key here, which groups flagged rows together such as overdue invoices marked red.
-
Open the Sort dialog from the Data tab.
-
Set Sort by to the relevant column.
-
Change Sort On to Cell Color, Font Color, or Conditional Formatting Icon.
-
Pick the color you want to surface and whether it sits On Top or On Bottom.
- Add more levels for additional colors, then click OK.
Method 7: Sort Entire Columns Left to Right
Most sorting reorders rows. Excel can also reorder entire columns horizontally, which suits data laid out with categories running across the top.
-
Open the Sort dialog.
-
Click the Options button.
- Select Sort left to right, then click OK.
- Pick the row number to sort by and set the order.
Excel rearranges your columns based on the values in that row while keeping each column's contents intact. The same Options button also toggles case-sensitive sorting.
Method 8: Sort Inside an Excel Table or With Filters
A formatted Excel table and any filtered range carry built-in sort controls in their headers.
-
Click the filter icon in any column header. (Turn on these arrows with the Filter button on the Data tab if they are missing.)
- Select Sort A to Z, Sort Z to A, Sort by Color, or Sort Smallest to Largest for numbers.
Sorting from the column heading keeps any active filters in place, which makes it the go-to for large datasets you are already slicing. Empty cells collect at the bottom, so clear stray blank cells first for a clean result.
Method 9: Sort With a Formula (SORT and SORTBY)
A sort formula uses Excel’s dynamic array functions to return a sorted version of a range or array without changing the original data. This suits dynamic data that updates often, because the result updates automatically the moment the source changes. Both the SORT function and the SORTBY function are available in Excel 365 and Excel 2021. An older version uses the Sort dialog or a helper column instead.
The SORT function orders a range by a chosen column:
=SORT(A2:D100, 3, 1)
=SORT(A2:D100, 3, 1)
The provided code appears to be a formula from a spreadsheet application like Excel, rather than C# code. If you have C# code that needs conversion to VB.NET, please provide that code.
That sorts the range by the third column in ascending order (use -1 for descending). The SORTBY function sorts one array based on a separate range or array, which handles more complex scenarios than SORT:
=SORTBY(A2:D100, C2:C100, 1)
=SORTBY(A2:D100, C2:C100, 1)
The provided C# code appears to be a formula from a spreadsheet application like Excel, rather than C# code. Therefore, it cannot be directly converted to VB.NET as it does not represent a C# programming construct. If you have a different C# code snippet that you would like converted to VB.NET, please provide that for conversion.
In the above example, the returned rows are sorted by the values in column C. Unlike manual sorting, these formulas spill a live result and recalculate automatically, so reports stay current with no extra clicks.
Method 10: Sort With a VBA Macro
For a report you rebuild every week, a macro repeats the same sort instantly. Open the Visual Basic editor with Alt + F11, insert a module, and paste a routine like this:
Sub SortByColumnB()
Range("A1:D100").Sort _
Key1:=Range("B1"), _
Order1:=xlAscending, _
Header:=xlYes
End Sub
Sub SortByColumnB()
Range("A1:D100").Sort _
Key1:=Range("B1"), _
Order1:=xlAscending, _
Header:=xlYes
End Sub
Sub SortByColumnB()
Range("A1:D100").Sort( _
Key1:=Range("B1"), _
Order1:=xlAscending, _
Header:=xlYes)
End Sub
This sorts the range by column B in ascending order. Run it from Developer > Macros, or assign it to a button on the sheet. The Header:=xlYes argument protects the header row.
Common Issues and Troubleshooting
A few recurring problems cause unexpected results. Here is how to fix each one.
Rows get scrambled and data ends up mismatched. This happens when only one column is highlighted and Excel sorts that column on its own. Click a single cell instead of selecting the whole column, or when the Sort Warning box appears, choose Expand the selection so every row moves together.
The header row gets sorted into the data. Open the Sort dialog box and tick My data has headers. Excel then locks the row of column headers in place.
Numbers sort in the wrong order. Values stored as text sort like words, so 10 lands before 2. Select the column, click the warning triangle, and choose Convert to Number, or use Data > Text to Columns to force a clean conversion.
A blank row or blank cells split the data. Excel treats an empty row or column as the edge of your table and sorts only one side. Remove stray blanks, or select the full data range manually before you sort.
Merged cells block the sort. Excel shows "This operation requires the merged cells to be identically sized." Unmerge the cells (Home > Merge & Center) and sort again.
Hidden rows stay put. Sorting skips hidden rows, so unhide everything before you sort to keep the data accurate.
For Developers: Sorting Columns in Code With IronXL
Teams that generate Excel data inside .NET apps often want sorting to run automatically, with no one opening the file. The IronXL C# Excel library handles this in a few lines and keeps every row aligned, the same way the Expand the selection option does in the desktop app.
using IronXL;
// Load an existing workbook
WorkBook workBook = WorkBook.Load("sales.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Select the data range below the header row
var dataRange = workSheet["A2:D100"];
// Reorder every row by the values in column C, smallest to largest
dataRange.SortByColumn("C", SortOrder.Ascending);
workBook.SaveAs("sales-sorted.xlsx");
using IronXL;
// Load an existing workbook
WorkBook workBook = WorkBook.Load("sales.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Select the data range below the header row
var dataRange = workSheet["A2:D100"];
// Reorder every row by the values in column C, smallest to largest
dataRange.SortByColumn("C", SortOrder.Ascending);
workBook.SaveAs("sales-sorted.xlsx");
Imports IronXL
' Load an existing workbook
Dim workBook As WorkBook = WorkBook.Load("sales.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet
' Select the data range below the header row
Dim dataRange = workSheet("A2:D100")
' Reorder every row by the values in column C, smallest to largest
dataRange.SortByColumn("C", SortOrder.Ascending)
workBook.SaveAs("sales-sorted.xlsx")
SortByColumn reorders the rows while keeping each record intact, and IronXL reads and writes standard .XLSX files with no Office install required on the server. For more patterns, including single-column sorts and descending order, see the sort Excel data examples.




