# Sorting Data

Course: [Excel](https://www.devtutorials.ai/learn/excel) · Section: Data Management
Source: https://www.devtutorials.ai/learn/excel/data-management/sorting-data

> Sort A to Z, Z to A, and by number, sort by several columns, and use custom sort orders.

A list is much easier to use when it is in order: names alphabetically, prices from lowest to highest, and dates from oldest to newest. **Sorting** rearranges whole rows so the data is in the order you need. In this lesson, you will sort A to Z and Z to A, sort numbers, sort by more than one column, and use a custom sort order.

Open the **Excel sandbox** and follow along. Sort tools are on the **Home** tab (**Sort & Filter**) and the **Data** tab.

Sorting moves **whole rows**, so each name stays with its own numbers. Before sorting, click **one cell** inside the table, or select the whole table. Never select just one column and sort it by itself, because that breaks the rows apart.

## A to Z sort

**A to Z** (ascending) puts text in alphabetical order.

1. Click any cell in the column you want to sort by, such as a name in column A.
2. Click **Sort & Filter** > **Sort A to Z**.

Excel recognizes the heading row and keeps it at the top.

## Z to A sort

**Z to A** (descending) puts text in reverse alphabetical order. Click a cell in the column, then choose **Sort & Filter** > **Sort Z to A**.

## Number sort

The same buttons sort numbers:

| Button | Numbers | Dates |
|---|---|---|
| **Sort Smallest to Largest** (A to Z) | 1, 5, 20, 100 | Oldest first |
| **Sort Largest to Smallest** (Z to A) | 100, 20, 5, 1 | Newest first |

If numbers sort strangely, like 1, 10, 100, 2, 20, they are stored as **text**. Text numbers align left. Type them again as real numbers, then sort again.

## Multi-level sort

Sometimes one column is not enough. For example, you might sort employees by **Department**, and then by **Name** inside each department.

1. Click a cell in the table.
2. Click **Sort & Filter** > **Custom Sort** or **Data** > **Sort**.
3. In the first level, choose **Sort by: Department**, **A to Z**.
4. Click **Add Level**, then choose **Then by: Name**, **A to Z**.
5. Click **OK**.

Excel sorts by the first level and uses the next level to break ties.

## Custom sort

Alphabetical order is not always the right order. Days of the week (`Mon, Tue, Wed`) or sizes (`Small, Medium, Large`) have their own natural order.

In the **Sort** dialog, open **Order** and choose **Custom List**. Pick a built-in list, like days or months, or type your own list (`Small, Medium, Large`) and click **Add**. Excel then sorts in that order.

Make sure your data has **no completely empty rows or columns** inside it. Excel treats a blank row as the end of the table, so rows below it will not be sorted.

## Common mistakes

| Mistake | What happens | How to fix it |
|---|---|---|
| Sorting one selected column only | Names no longer match their numbers | Undo right away, then click one cell and sort |
| Heading sorted into the data | The heading row moves down | Undo, and use the Sort dialog with **My data has headers** checked |
| Numbers stored as text | 1, 10, 100, 2… order | Convert them to numbers |
| A blank row in the table | Rows below it are not sorted | Delete the blank row, then sort |
| Custom order needed but A to Z used | Months sort April, August, December… | Use a custom list |

## Exercise

Click **Reset** in the sandbox header. Type this table in **A1:C6**:

| A | B | C |
|---|---|---|
| `Name` | `Team` | `Points` |
| `Maya` | `Blue` | `40` |
| `Leo` | `Red` | `55` |
| `Zara` | `Blue` | `55` |
| `Amir` | `Red` | `30` |
| `Kofi` | `Blue` | `25` |

Then do each task and press **Check**.

## What to remember

- Sorting moves **whole rows**. Click one cell in the table, and never sort a single column by itself.
- **A to Z** / **Z to A** are for text; **Smallest to Largest** / **Largest to Smallest** are for numbers and dates.
- **Custom Sort** adds levels: sort by one column, then break ties with another.
- **Custom lists** sort days, months, or your own order like Small, Medium, Large.
- Remove blank rows first, and make sure numbers are real numbers.

In the next lesson, you will filter data to show only the rows you need.
