Confident CellsExcel practice Start free

Grouping rows and the Subtotal command: practice exercises

Group, Ungroup, outline levels, Show Detail, Hide Detail, Clear Outline, Auto Outline, Subtotal, Remove All. 9 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 Group, Ungroup and Subtotal buttons above a practice sheet, with the outline's level buttons and + and − buttons beside the row numbers: group, fold and subtotal as you would in Excel, and each task is checked as you go.

Open the Grouping rows and the Subtotal command lesson

How it works

A long sheet is easier to read when you can fold parts of it away. Group some rows (or columns) and Excel puts a bar beside them with a − button: click it and they hide, leaving the total showing.

The Subtotal command does the grouping for you. Sort a list by region, say, and Subtotal puts a total under each region, a grand total at the bottom, and an outline with buttons 1, 2 and 3 to show more or less.

Group rows, then fold them away

A budget lists four bills in rows 2 to 5, then Bills total in row 6. To fold the bills away under their total, select rows 2 to 5 (click the row number 2, Shift-click 5) and choose Data, Group.

A bar appears to the left of the row numbers, with a − button by row 6. Click − and rows 2 to 5 hide; the button turns to +, which shows them again. Nothing is deleted, and the total still adds them up.

Columns work the same way: select columns B to D (the three months) and group them, and the bar and button sit above the column letters, by the Q1 total in column E.

Windows: Data, Outline, Group, or Alt+Shift+→. With only some cells selected, Excel asks Rows or Columns.

Mac: Data, Group, or Cmd+Shift+K.

Levels, Ungroup and Clear Outline

Above the bars are level buttons: 1, 2 and so on. 1 folds every group away; the highest number shows everything. With two groups in a budget, 1 leaves just the totals.

Show Detail and Hide Detail (on the Data tab) do what + and − do, for the group the active cell is in.

Ungroup (Alt+Shift+←) takes the selected rows out of their group. Clear Outline (under Ungroup) takes every group away. If a group was folded when you ungroup it, its rows stay hidden: select the rows either side and Home, Format, Hide & Unhide, Unhide Rows.

Auto Outline (under Group) groups a sheet for you from its SUM formulas: each total groups the rows it adds up.

Windows: Data, Outline, Ungroup ▾ for Clear Outline; Group ▾ for Auto Outline.

Mac: Data, Ungroup (Cmd+Shift+J), and the arrows beside Group and Ungroup for Auto Outline and Clear Outline.

The Subtotal command

A list of sales has a row for each sale: Region, Rep, Sales (£). Sort it by Region first, so each region's rows are together. Then click in the list and choose Data, Subtotal:

  • At each change in: Region. A new group starts each time the region changes, which is why the list must be sorted.
  • Use function: Sum (or Count, Average, Max, Min…).
  • Add subtotal to: tick Sales (£).

Excel inserts a row under each region, such as East Total with =SUBTOTAL(9,C2:C4), and a Grand Total at the bottom. The 9 means sum (1 is average, 3 count). The grand total uses SUBTOTAL too, so it leaves the region totals out and nothing is counted twice.

The rows are grouped for you: 1 shows just the grand total, 2 the region totals, 3 everything.

Windows: Data, Outline, Subtotal.

Mac: Data, Subtotal.

Change or remove subtotals

Run Subtotal again with Replace current subtotals ticked and the old subtotals go before the new ones are added: the way to change Sum to Average.

Untick it to add a second set under the first, such as an average for each region as well as a total.

Remove All, in the same box, takes every subtotal row and the outline away and leaves the list as it was.

Page break between groups starts each region on a new printed page, and Summary below data unticked puts the totals above each group instead.

Subtotal doesn't work in a table: Table Design, Convert to Range first.

What you'll practise

  1. Group the bill rows, rows 2 to 6, so they can be folded away under the Bills total. Click the row number 2, Shift-click 6, then Data, Group (or press Alt+Shift+→).
  2. Both lists are grouped. Fold them both away in one click, so only the totals show: click the outline's 1 button, at the top left of the sheet.
  3. Someone grouped the Bills total row (row 7) with the bills, so it hides with them. Take just that row out of the group: select row 7, then Data, Ungroup (or Alt+Shift+←).
  4. Group the three month columns, B to D, so they can be hidden and leave the Q1 total. Click the column letter B, Shift-click D, then Data, Group.
  5. The list is sorted by Region. Add a total of the sales under each region: click in the list, then Data, Subtotal. At each change in Region, Use function Sum, Add subtotal to Sales (£), OK.
  6. This list isn't sorted, and Subtotal starts a new group every time the region changes. Sort it by Region first (click a cell in column A, Data, A→Z), then add the Average sales for each region with Data, Subtotal.
  7. The manager wants the plain list back, with no subtotals. Click in the list, Data, Subtotal, then Remove All.
  8. Insert subtotals that show the total Amount (£) for each Category.
  9. Collapse the outline so that only the subtotals and the grand total are shown.