Confident CellsExcel practice Start free

Sorting on more than one column, and removing duplicates: practice exercises

Sort A to Z, the Sort dialog, Add Level, My data has headers, Remove Duplicates. 8 exercises on real-looking data, each checked as you go. The full lesson is part of Pro.

In the lesson

This lesson has Excel's Sort and Remove Duplicates boxes above a practice sheet: sort on several levels and remove repeated rows as you would in Excel, and each task is checked as you go.

Open the Sorting on more than one column, and removing duplicates lesson

How it works

The A→Z and Z→A buttons sort a list by one column. The Sort box does more: largest first, several levels (by Department, then by Salary within each department), and lists with no headings.

Remove Duplicates takes out repeated rows, keeping the first of each. You choose which columns have to match, such as just the Email column.

One click, one column

A staff list has First name, Last name, Department and Salary (£). Click any cell in the Last name column and choose Data, A→Z (Sort A to Z): Excel sorts the whole list by last name, and each person's row stays together.

Click one cell, not the whole column. Select just column B and Excel asks whether to expand the selection; sort only that column and the names no longer match their salaries.

Numbers sort smallest to largest with A→Z, and dates oldest to newest. Z→A is the other way.

Windows: Data, Sort & Filter, A→Z or Z→A (also on Home, Sort & Filter).

Mac: Data, Ascending or Descending (the A→Z and Z→A buttons).

The Sort box and levels

Data, Sort… opens the Sort box. Each line is a level: Sort by a column, Sort On Cell Values, and an Order (A to Z, Largest to Smallest, Oldest to Newest…).

To sort by Department, and within each department by Salary with the highest first: Sort by Department, A to Z; then Add Level and set Then by Salary (£), Largest to Smallest. Excel sorts by the first level, and only uses the next when two rows tie on it.

Delete Level takes a line out, Copy Level duplicates one, and the arrows change which comes first.

Windows: Data, Sort.

Mac: Data, Sort, then Add Level (the + under the list in some versions; − deletes a level).

My data has headers

At the top right of the Sort box, My data has headers tells Excel that row 1 is headings, so it stays at the top and the columns are listed by their headings.

Excel ticks it when row 1 looks like headings (text over numbers, or bold). A list with no headings needs it unticked; the columns are then called Column A, Column B…, and row 1 is sorted with the rest.

A table always has headers, so the box is ticked and greyed out.

Mac: the box is called My list has headers.

Remove Duplicates

Two sign-up sheets have been joined and some people are on both. Click in the list and choose Data, Remove Duplicates. Tick the columns that must match for two rows to count as the same, then OK. Excel keeps the first row of each and deletes the rest, then says, for example, 3 duplicate values found and removed; 9 unique values remain.

  • All columns ticked: a row only goes when every part of it matches an earlier row.
  • Only Email ticked: a row goes when its email is already on the list, even if the name is written differently.

Capitals don't matter (Excel counts leeds and Leeds as the same). There's no Undo button in the box, but Ctrl+Z undoes it straight after.

Windows: Data, Data Tools, Remove Duplicates (or Table Design, Remove Duplicates).

Mac: Data, Remove Duplicates.

What you'll practise

  1. Sort the staff list by Last name, A to Z. Click one cell in the Last name column (just one, so Excel sorts the whole list), then Data, A→Z.
  2. Put the highest salaries at the top. Use the Sort box: Data, Sort…, then Sort by Salary (£), Order Largest to Smallest, OK.
  3. Sort by Department A to Z, and within each department put the highest salary first. In the Sort box, Sort by Department (A to Z), then Add Level: Then by Salary (£), Largest to Smallest.
  4. This stock list has no headings: row 1 is an item like the rest. Sort it by the numbers in column B, smallest first. In the Sort box, untick My data has headers (Excel then calls the columns Column A and Column B), and sort by Column B, Smallest to Largest.
  5. Some people were entered twice when two sign-up sheets were joined. Remove the repeated rows: click in the list, then Data, Remove Duplicates, keep every column ticked, OK. Excel says how many it removed.
  6. Each email address should only be on the list once, but two people signed up twice with their names written differently. Remove the rows with an Email already on the list: in Remove Duplicates, tick only Email.
  7. Sort the table by Region in alphabetical order and then by Date from oldest to newest.
  8. Remove the records from the table that have a duplicate Order value. Do not remove any other records.

Guides with worked examples: UNIQUE and FILTER: lists that update themselves · SORT and SORTBY: sorted lists that keep up