Sorting and filtering

Sort rows by one or several columns, filter a list by value or condition, reapply and clear filters, and filter with a criteria range using Advanced Filter.

Sorting reorders whole rows. Filtering hides the rows you don’t want to see without deleting them. For filters that show on the sheet as buttons, see Slicers and Timelines.

Sort by one column

  1. Select the data to sort, including its header row. If you select a single cell, all the data on the sheet is sorted.
  2. Put the current cell in the column to sort by. When you select by dragging, the current cell is the one you finished on.
  3. Choose Sort A to Z or Sort Z to A, from Data › Sort & filter or from the Sort menu in Home › Editing.

How sorting works:

  • The first row of the selection is treated as a header and stays at the top.
  • Whole rows move together, across every column of the selection. A column is never sorted on its own.
  • In Sort A to Z, numbers come before text, and text is sorted without regard to capitals.
  • Empty cells go to the bottom in both directions.

Sort by several columns

  1. Select the data, including its header row.
  2. Choose Data › Sort & filter › Sort…, or Home › Editing › Sort › Custom sort….
  3. In the Sort dialog, set up the levels:
ControlWhat it does
Sort byThe first column to sort by. Columns are listed by letter and heading, such as B — Region, or Column B when the column has no heading.
A → Z / Z → AClick to switch the direction for that level
then byFurther levels. Each one breaks the ties left by the levels above it.
Add a levelAdds a level, up to four
× (Remove this level)Removes a level
First row is a headerOn: the first row stays in place. Off: it is sorted with the rest.
  1. Click Sort.

The dialog shows the range it will sort, such as Sorting A1:F120.

Filter a list

Turn on filters

  1. Select the list, including its header row. If you select a single cell, all the data on the sheet is used.
  2. Turn filters on with the funnel button in Data › Sort & filter (Turn on filters), Home › Editing › Sort › Filter, or Filter in the More menu.

The funnel button is highlighted while filters are on for the sheet.

Filter a column

  1. Click a cell in the column to filter.
  2. Click Data › Sort & filter › Filter…. (The button is unavailable until filters are on.)
  3. In the dialog titled Filter and the column’s letter, choose what to keep:
OptionWhat it does
Where the value isno condition, greater than, less than, equal to, contains or begins with
ValueThe value to compare with. Appears once you choose a condition. greater than and less than compare numbers. equal to compares numbers when both sides are numbers, and text otherwise. contains and begins with compare text. Text comparisons ignore capitals.
VALUESA tick box for each different value in the column. Untick the values to hide. All ticks every value and None clears them all.
  1. Click Apply.

A row stays visible only if its value is ticked and meets the condition. The header row is never hidden. The status bar says how many rows are hidden, for example 14 rows hidden by the filter., or Showing every row.

Filters on different columns combine: a row must pass all of them. To remove one column’s filter, open its Filter dialog and click Clear.

Reapply filters

A filter is applied when you set it. If you then change the data, rows don’t hide or reappear on their own. To run the filters again over the current data, click the reapply button in Data › Sort & filter, or Reapply in Home › Editing.

The status bar says Reapplied: followed by the number of hidden rows, Reapplied — every row now passes., or There are no filters on this sheet to reapply.

Clear filters

Click Data › Sort & filter › Clear. Every filter on the sheet is removed and the rows they hid come back. The status bar says Filters cleared. The button is unavailable when nothing is filtered.

Rows you hid yourself with Hide rows stay hidden.

Advanced Filter

Advanced Filter filters a list by a criteria range — a small table of conditions on the sheet. It can express “this or that”.

Set up a criteria range

  1. Somewhere outside the list, copy the headings of the columns you want to test into a row.
  2. In the rows below the headings, type the conditions:
    • Conditions in the same row must all be true.
    • Each row is an alternative: a list row passes if it meets any one row of conditions.

For example, this criteria range keeps rows from North with sales over 1000, and every row from South:

RegionSales
North>1000
South

What you can type in a condition cell:

ConditionMatches
NorthValues that begin with North (so Northern matches too)
>1000, <50, >=10, <=10Numbers greater than, less than, at least or at most the value. With text, the comparison is alphabetical.
<>0Values that are not 0
Sm*th, J?nWildcards: * stands for any run of characters and ? for one character

A completely empty condition row matches every row, so don’t leave a blank row inside the criteria range.

For a condition that no column heading can express, leave the criteria heading cell empty and type a formula below it, written for the list’s first data row — for example =C2>AVERAGE($C$2:$C$50). It is checked for each row in turn, with its relative references moved down to that row.

Run the filter

  1. Select the list, including its header row.
  2. Choose Data › Sort & filter › Advanced….
  3. Fill in the dialog:
OptionWhat it does
List rangeShows the list that will be filtered — the selection, or all the data on the sheet. Select the list before opening the dialog.
Criteria rangeThe address of the criteria range, headings included, such as F1:G3. Leave it blank to filter on uniqueness only.
Filter the list in placeHides the rows that don’t pass
Copy to another placeLeaves the list alone and copies the rows that pass to Copy to
Unique records onlyLeaves out rows that repeat an earlier row
Copy toFor Copy to another place: the top-left cell of the destination, such as A20. To copy only some columns, type their headings in that row first.
  1. Click Filter.

The status bar says, for example, 8 of 120 rows shown. or 8 rows copied to A20.

If something is wrong, the dialog stays open and explains:

MessageWhat to do
The list needs a header row and at least one row of data.Select the list with its header row.
The criteria range needs a header row and at least one row of conditions.Include the headings and at least one row below them.
The criteria range names a column called ”…”, which the list does not have.Make the criteria heading match a list heading exactly (capitals don’t matter).
The destination asks for a column called ”…”, which the list does not have.Correct the headings in the Copy to row.
cell is inside the list being filtered.Choose a destination outside the list.
The results will not fit below and to the right of the destination.Choose a destination with more room.
”…” is not a range. or ”…” is not a cell reference.Type an address such as F1:G3 or A20.

To show every row again after filtering in place, run Advanced… again with Criteria range empty and Unique records only off, or press ⌘Z (Ctrl+Z) straight after filtering.

Something unclear or out of date on this page? Tell us.