Lesson 20 of 92 · Free Excel Course
Excel
Excel Sort and Filter: Buttons, Custom Sorts and the FILTER Formula
Sort Excel data A to Z or by several columns, filter by text, number, date or colour, and use the FILTER, SORT and SORTBY formulas, with a practice file.
A list is only useful if you can find things in it. Who sold the most? Which orders came from the West? Which jobs are high priority? Excel gives you two ways to answer questions like these. The Sort and Filter buttons rearrange or hide rows in your list with a few clicks. The FILTER, SORT and SORTBY functions build a separate, always-up-to-date copy of just the rows you want. This lesson covers both, using one small sales list, so you can choose the right tool each time.
Sort a list A to Z or Z to A
Here's the sales list used all through this lesson. It's in no particular order.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Rep | Region | Product | Sales | Priority |
| 2 | Carla | East | Desks | $310 | Medium |
| 3 | Ben | West | Desks | $95 | Low |
| 4 | Hana | West | Chairs | $150 | Medium |
| 5 | Ann | East | Chairs | $120 | High |
| 6 | Ella | West | Lamps | $180 | High |
| 7 | Dev | North | Chairs | $60 | Low |
| 8 | Gus | East | Lamps | $75 | Low |
| 9 | Femi | North | Desks | $240 | Medium |
To put the biggest sales at the top:
- Click any one cell in the Sales column, such as D2. Don't select the whole column.
- Go to the Data tab. In the Sort & Filter group, click Sort Largest to Smallest (the button with Z above A and a down arrow).
- Carla ($310) is now in row 2 and Dev ($60) is at the bottom.
For text, the same buttons are called Sort A to Z and Sort Z to A; for dates, Sort Oldest to Newest and Sort Newest to Oldest. You'll also find them on the Home tab under Sort & Filter. Excel notices that row 1 is headings and leaves it in place.
On a Mac, the Data tab has Ascending and Descending buttons that do the same job. In Excel for the web, they're called Sort Ascending and Sort Descending on the Data tab.
Don't scramble your rows: the "Expand the selection" warning
The most damaging sorting mistake is selecting one column and sorting it. Excel then asks what you want in a Sort Warning box:
- Expand the selection sorts the whole table, so each rep keeps their own region, product and sales figure. This is almost always what you want.
- Continue with the current selection sorts only the column you picked. The names move but everything else stays put, so Carla's $310 might end up next to Dev's name. Your data is now wrong, and nothing on screen tells you.
If that happens, press Ctrl+Z (Cmd+Z on a Mac) straight away to undo. The safe habit is simple: click a single cell inside the list and let Excel work out the edges. A completely blank row or column inside your data can make Excel stop short, so remove those first.
Sort by more than one column
Say you want the list grouped by region, and inside each region the biggest sales first. That needs two levels in the Sort dialog.
- Click a cell in the list.
- On the Data tab, click Sort (the large button between the A to Z buttons and Filter). The Sort dialog opens.
- Check that My data has headers is ticked.
- Under Sort by, choose Region. Leave Sort On as Cell Values and Order as A to Z.
- Click Add Level. In the new Then by row, choose Sales and set Order to Largest to Smallest.
- Click OK.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Rep | Region | Product | Sales | Priority |
| 2 | Carla | East | Desks | $310 | Medium |
| 3 | Ann | East | Chairs | $120 | High |
| 4 | Gus | East | Lamps | $75 | Low |
| 5 | Femi | North | Desks | $240 | Medium |
| 6 | Dev | North | Chairs | $60 | Low |
| 7 | Ella | West | Lamps | $180 | High |
| 8 | Hana | West | Chairs | $150 | Medium |
| 9 | Ben | West | Desks | $95 | Low |
You can add more levels the same way, and use Delete Level or the up and down arrows to change their order; the top level wins. On a Mac, the Sort dialog is under Data, then Sort (or Cmd+Shift+R), and also has an Add Level button. In Excel for the web, click Data, then Custom Sort.
Sort by colour and by a custom list
Sort by colour. If you've shaded some cells (see Format cells), you can bring them to the top. In the Sort dialog, set Sort On to Cell Color (or Font Color), pick the colour under Order, and choose On Top. Add a level per colour if you have several. Microsoft notes that in Excel for the web the Sort On box is unavailable, so colour sorting needs the desktop app.
Sort by a custom list. A to Z puts months in the wrong order (April, August, December...) and puts High, Low, Medium in alphabetical order rather than priority order. Custom lists fix that.
- Open the Sort dialog and choose the column, such as Priority.
- Under Order, choose Custom List.
- Pick a built-in list like January, February, March. For your own order, type it in List entries, one item per line: High, Medium, Low. Click Add, then OK.
- Click OK to sort.
You can also save a list for good under File, Options, Advanced, then Edit Custom Lists in the General section. On a Mac it's Excel, Preferences, Custom Lists.
Turn on filters (AutoFilter)
Filtering hides the rows you don't want to see, without deleting anything.
- Click a cell in the list.
- Press Ctrl+Shift+L, or click Data, then Filter. A small arrow appears in every heading cell.
- Click the arrow on Region. Untick (Select All), tick West, and click OK.
Now only Ben, Hana and Ella show. The row numbers turn blue and skip, and the Region arrow changes to a funnel icon, both signs that a filter is on. On a Mac, the shortcut is Cmd+Shift+F; in Excel for the web, Ctrl+Shift+L works as well.
Filter by text, number, date and colour
The arrow menu changes depending on what's in the column:
- Text Filters on a text column: Contains, Begins With, Equals and more.
- Number Filters on numbers: choose Greater Than, type 100, and click OK to see the five sales over $100. Top 10 lets you pick the top (or bottom) few; set it to 3 items to see Carla, Femi and Ella.
- Date Filters on dates: ready-made choices such as This Month, Last Month or Year to Date, which follow the calendar automatically.
- Filter by Color when the column has shaded cells or coloured text: pick a colour to see only those rows.
You can filter several columns at once. Each one narrows the list further, so West plus Greater Than 100 leaves just Hana and Ella.
Clear and reapply filters
- Clear one column: click its funnel icon and choose Clear Filter From "Region".
- Clear every filter: on the Home tab, click Sort & Filter, then Clear. All rows come back and the arrows stay.
- Remove the arrows completely: press Ctrl+Shift+L again or click Data, then Filter.
- Reapply: if you edit the data, a filter doesn't update itself. Click Home, Sort & Filter, then Reapply to run it again.
Filter with a formula: the FILTER function
The Filter button hides rows in place. The FILTER function copies matching rows to a new spot and keeps them up to date:
=FILTER(array, include, [if_empty])
- array is the data to return, here
A2:E9. - include is the test, such as
B2:B9="East". - if_empty is optional: what to show if nothing passes.
Type it once in the top-left cell of an empty area and press Enter:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Rep | Region | Product | Sales | Priority |
| 2 | Carla | East | Desks | $310 | Medium |
| 3 | Ben | West | Desks | $95 | Low |
| 4 | Hana | West | Chairs | $150 | Medium |
| 5 | Ann | East | Chairs | $120 | High |
| 6 | Ella | West | Lamps | $180 | High |
| 7 | Dev | North | Chairs | $60 | Low |
| 8 | Gus | East | Lamps | $75 | Low |
| 9 | Femi | North | Desks | $240 | Medium |
| 10 | |||||
| 11 | East orders | ||||
| 12 | Carla | East | Desks | $310 | Medium |
| 13 | Ann | East | Chairs | $120 | High |
| 14 | Gus | East | Lamps | $75 | Low |
The shaded block is the spill range. Change Ann's region to West and she disappears from the result instantly; no Reapply needed. FILTER doesn't copy headings, so type those yourself above the formula if you want them. You can also point the test at a cell, like B2:B9=H1, and just type a new region in H1.
More than one condition: AND and OR
Put each test in brackets, then:
- Multiply them for AND (both must be true):
=FILTER(A2:E9,(B2:B9="West")*(D2:D9>100))returns Hana and Ella. Ben is West but only $95. - Add them for OR (either can be true):
=FILTER(A2:E9,(C2:C9="Lamps")+(D2:D9>200))returns Carla ($310), Ella (Lamps), Gus (Lamps) and Femi ($240).
The brackets matter. Without them, Excel does the multiplication before the comparisons and you get the wrong rows or an error.
When nothing matches: #CALC! and if_empty
There are no South orders, so =FILTER(A2:E9,B2:B9="South") shows #CALC!. Excel can't display an empty result. Add the third argument to show a message instead:
=FILTER(A2:E9,B2:B9="South","No orders") shows No orders. Use "" if you'd rather the cell stayed blank.
SORT and SORTBY: sorting with a formula
SORT returns a sorted copy of a range: =SORT(array, [sort_index], [sort_order]). The sort_index is the column number inside the range, and the sort_order is 1 for ascending (the default) or -1 for descending. =SORT(A2:E9,4,-1) lists all eight rows biggest sale first.
The two go together nicely. Wrap FILTER inside SORT to get the sales over $100, largest first:
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 26 | Over $100, biggest first | ||||
| 27 | Carla | East | Desks | $310 | Medium |
| 28 | Femi | North | Desks | $240 | Medium |
| 29 | Ella | West | Lamps | $180 | High |
| 30 | Hana | West | Chairs | $150 | Medium |
| 31 | Ann | East | Chairs | $120 | High |
SORTBY sorts one range by another, which doesn't even have to be part of the result. =SORTBY(A2:A9,D2:D9,-1) lists just the rep names in sales order: Carla, Femi, Ella, Hana, Ann, Ben, Gus, Dev. Add more pairs for extra levels, like =SORTBY(A2:E9,B2:B9,1,D2:D9,-1) for region then sales.
UNIQUE, briefly: =UNIQUE(B2:B9) lists each region once (East, West, North), and =SORT(UNIQUE(B2:B9)) puts them in order. It gets its own lesson later: Find and remove duplicates.
FILTER, SORT, SORTBY and UNIQUE work in Microsoft 365 (Windows and Mac), Excel 2021, Excel 2024 and Excel for the web. They aren't in Excel 2019 or earlier, which typically shows #NAME?. The Sort and Filter buttons work everywhere.
Buttons or formulas?
| Use the buttons when... | Use the formulas when... |
|---|---|
| You want a quick look | You want a report that updates itself |
| You're happy to change the list's order | The original list must stay as it is |
| You need colour sorting or filtering | You want results on another sheet |
| Anyone might open the file in Excel 2019 | Everyone has Excel 2021 or newer |
Try it yourself
Download the practice workbook and open the Practice sheet. Yellow cells are where you type.
- Click D2 and sort Largest to Smallest. Carla should be first and Dev last. Check against the Sorted sheet.
- Open the Sort dialog and sort by Region A to Z, then Sales Largest to Smallest.
- Sort by Priority using a custom list: High, Medium, Low.
- Press Ctrl+Shift+L, filter Region to West, then add Number Filters, Greater Than 100. You should see Hana and Ella. Clear the filters.
- In A12, type
=FILTER(A2:E9,B2:B9="East"). In A17 and A21, try the AND and OR versions. - In A27, type
=SORT(FILTER(A2:E9,D2:D9>100),4,-1). In A34, filter for South with "No orders" as the message. - In G2, type
=SORTBY(A2:A9,D2:D9,-1), and in I2,=UNIQUE(B2:B9).
The Answers sheet has every formula working.
Common mistakes
- Sorting one column on its own. Choosing "Continue with the current selection" breaks every row. Undo at once.
- Blank rows in the data. Excel may treat them as the end of the list and only sort or filter the top part.
- Forgetting a filter is on. Hidden rows still exist. Blue row numbers and funnel icons are the clue.
- #SPILL! A FILTER or SORT result needs empty cells to spill into. If anything is in the way, you get #SPILL!; click the error and choose Select Obstructing Cells, then clear them.
- #CALC! from FILTER. Nothing matched. Add an if_empty message.
- Missing brackets in AND/OR. Write
(B2:B9="West")*(D2:D9>100), with each test in its own brackets. - Ranges of different heights.
=FILTER(A2:E9,B2:B8="East")won't work: the test must cover the same rows as the array.
What's next
You can now put any list in order and show just the rows you need, by clicking or with a formula. The next lesson, Find and remove duplicates, uses some of the same tools to clean up repeated entries. You can also revisit XLOOKUP and INDEX MATCH or go back to the full Excel course.
Frequently asked questions
How do I filter with more than one condition in a formula?
Wrap each condition in brackets and multiply them for AND, or add them for OR. =FILTER(A2:E9,(B2:B9="West")*(D2:D9>100)) keeps rows that are West and over 100. =FILTER(A2:E9,(C2:C9="Lamps")+(D2:D9>200)) keeps rows that are Lamps or over 200.
Why does my FILTER formula show #CALC!?
Nothing matched your condition, and Excel can't show an empty result. Add a third argument to say what to show instead, such as =FILTER(A2:E9,B2:B9="South","No orders").
What's the difference between the Filter button and the FILTER function?
The Filter button (AutoFilter) hides rows in your original list, and you change it by clicking. The FILTER function leaves the list alone and copies the matching rows somewhere else, and it updates by itself when the data changes. Use the button for a quick look, the formula for a report that stays up to date.
How do I sort in Excel without mixing up the rows?
Click one cell inside the list (don't select a single column) and then click Sort A to Z. Excel sorts the whole table so each row stays together. If Excel shows a Sort Warning, pick Expand the selection.
What is the shortcut to turn filters on and off?
Ctrl+Shift+L on Windows and in Excel for the web. On a Mac it's Cmd+Shift+F (Ctrl+Shift+L also works). It's on our Excel shortcuts cheat sheet.
Why don't I have the FILTER or SORT function?
They're in Microsoft 365, Excel 2021, Excel 2024 and Excel for the web, but not in Excel 2019 or earlier, where the formula typically shows #NAME?. The Sort and Filter buttons work in every version. You can also use the free Excel for the web.