How to Sort Data in Excel: A Complete Guide

Learn how to sort data in Excel by text, numbers, dates, multiple columns, custom lists, color, and formulas without breaking rows.

Sorting in Excel rearranges records so the values you care about are easier to scan. You might put the earliest due date first, rank sales from highest to lowest, group tasks by team, or apply several rules in sequence.

The commands are simple; the important part is choosing the complete data set and keeping each row intact. This guide starts with a safe sorting routine, then covers multi-level sorts, custom orders, colors, common data problems, and the SORT and SORTBY functions.

What sorting changes in Excel

A standard sort rearranges the selected cells in place. When you sort a complete list by its Due date column, Excel moves each full record so the task, owner, priority, and date stay together. It does not change the values themselves.

Ascending and descending labels depend on the data type:

Data type Ascending Descending
Text A to Z Z to A
Numbers Smallest to Largest Largest to Smallest
Dates and times Oldest to Newest Newest to Oldest

If you need the source list to stay in its current order, use a formula that produces a separate sorted result instead of an in-place sort. That option appears later in the guide.

Prepare the list before sorting

A minute of preparation prevents most sorting mistakes. Use one header row, keep one record per row, and avoid completely blank rows or columns inside the list. A unique ID column is also valuable because it identifies each record even after the row position changes.

  1. Save the workbook or confirm that Undo is available.
  2. Check that every column has a clear, unique heading.
  3. Make sure each row is one complete record.
  4. Unmerge cells in the data area; merged cells can block a sort.
  5. Check that numbers and dates are stored as real numbers and dates rather than text.
  6. Optionally add an Original order column numbered 1, 2, 3, and so on, so you can restore the starting sequence later.

Protect row integrity: sort the whole data range, not one isolated column. Moving a single column by itself can attach names, dates, or amounts to the wrong records.

Sample task list

The examples below use a task list in A1:G8. The Task ID makes each record easy to recognize after a sort.

Task ID Owner Team Priority Due date Hours Status
T-104MinaDesignHigh7 Oct 20266In progress
T-101OmarOperationsCritical2 Oct 20263Open
T-107LinaDesignMedium12 Oct 20268Open
T-103NoahFinanceHigh5 Oct 20264In progress
T-106SamOperationsLow15 Oct 20262Blocked
T-102AyaFinanceCritical2 Oct 20267Open
T-105YaraDesignMedium10 Oct 20265Done

Quick-sort by one column

Use a quick sort when one rule is enough. To put the earliest task deadline first:

  1. Select one cell in the Due date column. You do not need to select the whole column.
  2. Open the Data tab.
  3. In the Sort & Filter group, choose Sort Oldest to Newest.
  4. Check two or three rows to confirm that every task record moved together.

For text, the same buttons appear as Sort A to Z and Sort Z to A. For numbers, they become Sort Smallest to Largest and Sort Largest to Smallest. Excel chooses the labels from the data it recognizes in the selected column.

If Excel asks whether to expand the selection, choose Expand the selection when the adjacent columns belong to the same records. Choose Continue with the current selection only when you deliberately want to reorder those cells independently.

Sort by multiple columns

A multi-level sort resolves ties in a controlled order. Suppose you want the task list grouped by Team, with the earliest due date first inside each team. Team is the first level; Due date is the second.

  1. Select any cell in the list.
  2. Choose Data > Sort.
  3. Confirm that My data has headers is selected.
  4. For Sort by, choose Team. Keep Sort On set to Cell Values and choose A to Z.
  5. Select Add Level.
  6. For Then by, choose Due date, then choose Oldest to Newest.
  7. Select OK and inspect the groups.

Levels are applied from top to bottom. Excel first groups identical Team values, then uses Due date only to order records within each team. Move a level up or down in the Sort dialog when you need to change that precedence.

Microsoft’s sorting guide for ranges and tables documents the current dialog options, including multi-level sorts.

Apply a business order with a custom list

Alphabetical order is wrong for values such as Critical, High, Medium, and Low. A custom list tells Excel the sequence the business uses.

  1. Select a cell in the task list and open Data > Sort.
  2. Choose Priority in the Sort by box.
  3. Open the Order menu and choose Custom List.
  4. Create or select the sequence Critical, High, Medium, Low.
  5. Select OK to return to the Sort dialog, then select OK again.

Excel already includes custom lists for month and weekday names. You can also create your own list in the desktop app or import one from worksheet cells. Microsoft explains both methods in its custom-list sorting instructions.

Sort by color, font color, or icon

Excel can sort by formatting as well as by cell values. This is useful when a fill color or conditional-formatting icon has a defined meaning—for example, a red fill for blocked work.

  1. Select a cell in the relevant column and open Data > Sort.
  2. Choose the column that contains the formatting.
  3. Under Sort On, choose Cell Color, Font Color, or Cell Icon.
  4. Under Order, choose a color or icon and place it on top or on the bottom.
  5. Add another level for each additional color or icon whose position matters.

Colors and icons do not have a built-in ascending order. You define their positions one level at a time. If color represents a real category, a separate Status or Priority column is usually easier to audit and reuse in formulas.

Sort an Excel Table

An Excel Table is a strong default for a list that changes frequently. Select the range and choose Insert > Table, or press Ctrl + T on Windows. Confirm the range and indicate that the table has headers.

Each table header receives a filter button. Open the button for the column you want and choose the appropriate ascending or descending command. Table rows expand as new records are added, which reduces the chance that a later sort will omit recently entered data.

A standard range or table sort rearranges the source records. If you want a live sorted view while preserving the source order, use SORT or SORTBY.

Create a separate sorted view with SORT

The SORT function returns a dynamic array, so its result spills into neighboring cells without moving the source. In current Excel versions that support dynamic arrays, this formula sorts the sample range by its fifth column, Due date, in ascending order:

=SORT(A2:G8,5,1)

The arguments are the source array, the column index within that array, and the sort order. Use 1 for ascending or -1 for descending. Because Due date is the fifth column of A2:G8, the sort index is 5.

If your regional settings use semicolons as formula separators, replace the argument-separating commas with semicolons.

Leave enough empty cells below and to the right of the formula for the result. If another value blocks that area, Excel returns #SPILL!. The source is unchanged, and edits to the source recalculate the sorted view.

Sort more flexibly with SORTBY

SORTBY points directly to the column or array that controls the order. This makes the formula easier to maintain when columns are added or removed. To sort by Team and then Due date, enter:

=SORTBY(A2:G8,C2:C8,1,E2:E8,1)

The first pair sorts Team ascending; the second pair breaks ties by Due date ascending. Each sort range must align with the rows in the returned array.

You can also reproduce the custom priority order in a dynamic formula:

=SORTBY(A2:G8,XMATCH(D2:D8,{"Critical","High","Medium","Low"}),1,E2:E8,1)

XMATCH converts each priority label into its position in the stated list. SORTBY orders those positions from 1 to 4, then uses Due date to order tasks with the same priority. Every source label must match an item in the priority list; otherwise XMATCH returns #N/A.

SORT and SORTBY are available in Microsoft 365, Excel 2021, and Excel 2024, including supported Mac and mobile editions. See Microsoft’s references for the SORT function and SORTBY function for syntax and platform details.

Sort columns from left to right

Most Excel sorts move rows from top to bottom. A desktop range can also be sorted horizontally:

  1. Select a cell in the range.
  2. Open Data > Sort, then select Options.
  3. Choose Sort left to right and select OK.
  4. Choose the row that controls the order, set the order, and select OK.

Excel Tables do not support left-to-right sorting. Convert the table to a normal range first if the horizontal sort is necessary, and keep a backup because that conversion removes table behavior.

Fix sorting results that look wrong

Problem Likely cause Fix
1, 10, 100, 2 Some or all numbers are stored as text. Convert the entries to real numbers, then sort again. Changing only the visual number format may not convert the underlying text.
Dates sort alphabetically The entries are text rather than Excel date values. Convert the text to valid dates and verify that Excel recognizes them before sorting.
Names or categories appear out of place Leading spaces, nonprinting characters, or inconsistent spelling are present. Clean imported text with functions such as TRIM and standardize labels.
The header is mixed into the data My data has headers was cleared or Excel did not recognize the heading row. Undo, reopen the Sort dialog, and mark the data as having headers.
Related values no longer match Only one column was sorted. Undo immediately, then sort the complete range or choose Expand the selection.
New rows did not move The selected range stopped before the new records. Expand the range or convert it to an Excel Table before sorting.
#SPILL! from SORT or SORTBY A value or merged cell blocks the formula’s output area. Clear or move the obstruction, or place the formula in a larger empty area.

Sort order can also vary with regional settings, especially for text. If a shared workbook produces an unexpected alphabetic sequence on another computer, compare the operating-system locale and Excel language settings.

Frequently asked questions

How do I restore the original order after sorting?

Use Undo if no later action needs to be preserved. For a repeatable solution, add an Original order column before sorting and fill it with sequential numbers. Sort that column from smallest to largest whenever you need the initial sequence.

Why does Excel sort only part of my data?

A blank row or column may divide the list, the selected range may be incomplete, or you may have chosen to continue with the current selection. Convert the list to a Table or select the complete rectangular range before sorting.

How do I sort without changing the original list?

Use SORT or SORTBY in a separate empty area. The formula returns a live sorted copy while the source remains in place.

What is the difference between sorting and filtering?

Sorting changes the order of records. Filtering keeps the order but temporarily hides records that do not meet the selected criteria. You can use both on the same range or Table.

Can Excel sort uppercase and lowercase letters separately?

Yes in the desktop Sort dialog. Select Options, enable Case sensitive, and run the sort. Standard sorts are not case-sensitive.

Choose the method that matches the outcome

Use a quick sort for one straightforward rule. Open the full Sort dialog when ties, business priorities, colors, or several columns matter. Use an Excel Table for lists that grow, and choose SORT or SORTBY when you need a separate result that updates without rearranging the source.

Whatever method you use, the safety rule stays the same: treat each row as one record and move all of its fields together. A short check of the headers, data types, and selected range is far easier than repairing a list whose columns no longer match.