How to Add Expand and Collapse in Excel

How-to basics · Updated November 25, 2026

To add expand and collapse in Excel, you use the Group feature (Data > Outline > Group). This lets you hide or show rows or columns with a single click, making large datasets easier to navigate. Grouping works for both contiguous ranges and, with a few extra steps, for non-adjacent sections. You can also create collapsible sections with subtotals or use a macro for more advanced toggling. Here’s the full step-by-step process.

What You’ll Need

  • Microsoft Excel for Microsoft 365 on Windows (steps differ slightly on Mac and Excel for the web, noted below).
  • A worksheet with rows or columns you want to collapse—typically a data table with a header row and logical groupings (e.g., quarterly totals, product categories).
  • No special add-ins or formulas are required; grouping is built into Excel.

Step-by-Step

  1. Select the rows or columns to group. Click and drag across the row numbers (on the left) or column letters (on top) to highlight the entire rows or columns you want to collapse. For example, to group rows 2 through 5, click row 2’s number, hold Shift, then click row 5’s number.
  2. Open the Group dialog. Go to the Data tab on the ribbon. In the Outline group (usually on the far right), click Group. A small dialog appears asking whether you want to group rows or columns. Choose Rows or Columns based on your selection, then click OK.
  3. See the outline buttons. After grouping, Excel adds a gray bar with a minus sign (−) to the left of the row numbers (or above the column letters). Click that minus sign to collapse the group; it turns into a plus sign (+) that expands it again.
  4. Group multiple levels. To create nested groups (e.g., group months within a quarter), select the inner range first and group it, then select the outer range (including the inner group) and group again. Excel displays multiple outline bars, each with its own plus/minus buttons.
  5. Use the outline numbers. Above the row numbers (or to the left of column letters), you’ll see small numbers (1, 2, 3, etc.). Click 1 to collapse all groups to the top level, 2 to show one level down, and so on. This is faster than clicking each plus/minus individually.
  6. Add a subtotal row (optional). If you want a collapsible section with a summary, insert a subtotal row at the end of each group (e.g., using the SUBTOTAL function). For example, with sales in B2:B10 and a subtotal in B11, use =SUBTOTAL(9,B2:B10) to sum only visible cells. Then group the detail rows (B2:B10) but leave the subtotal row ungrouped. When collapsed, only the subtotal shows.
  7. Group non-adjacent rows or columns. If your groups are not next to each other, you cannot select them all at once. Instead, group each range separately. For instance, group rows 2–5, then group rows 8–12. Each becomes its own collapsible section.
  8. Ungroup when needed. Select the grouped rows or columns, go to Data > Ungroup, and choose Rows or Columns. To clear all grouping, select the entire sheet (Ctrl+A twice), then Data > Ungroup > Clear Outline.

Mac difference: On Excel for Mac, the Group command is under Data > Group (same dialog). The outline buttons appear on the left, but the numbers are on the top-left corner. Keyboard shortcut: Shift+Alt+Right Arrow to group, Shift+Alt+Left Arrow to ungroup (on Windows); on Mac, use Command+Shift+K to group and Command+Shift+J to ungroup.

Excel for the web: Grouping is available in Excel for the web, but the outline bars are less prominent. Go to Data > Group and select rows or columns. The plus/minus buttons appear, but the level numbers (1,2,3) are not shown; you can only click individual plus/minus signs.

Common Mistakes

  • Grouping the wrong range – If you include the subtotal row in the group, the subtotal hides when collapsed. Always leave summary rows outside the grouped range.
  • Selecting entire columns instead of just the data – This can group the whole sheet, causing unexpected behavior. Only select the rows/columns you need.
  • Forgetting to clear outline before sorting – If you sort data that has groups, the groups may break or hide wrong rows. Ungroup first, then sort.
  • Using plus/minus on filtered data – Grouping and AutoFilter can conflict. When a filter is active, collapsing a group may hide rows that the filter would otherwise show, leading to confusion.

Tips

  • Use keyboard shortcuts for speed: On Windows, select rows/columns and press Shift+Alt+Right Arrow to group, Shift+Alt+Left Arrow to ungroup. On Mac, use Command+Shift+K and Command+Shift+J.
  • Name your groups with a header row: Keep a clear header row above each group (e.g., “Q1 Sales”) so that when collapsed, the header remains visible. This makes the outline more readable.
  • Combine with SUBTOTAL for dynamic summaries: Use =SUBTOTAL(9,range) for sums, =SUBTOTAL(1,range) for averages, etc. These functions ignore hidden rows, so your subtotal updates correctly when groups collapse.
  • Collapse all at once: Click the number 1 in the outline bar to collapse everything to the top level. Click 2 to expand one level, and so on.
  • Use group for printing: If you collapse groups before printing, only visible rows print. This is handy for executive summaries.

Troubleshooting

  • No plus/minus buttons appear after grouping: Check that you selected entire rows or columns, not just cells. Also, ensure the outline bar is visible: go to File > Options > Advanced, scroll to “Display options for this worksheet,” and check “Show outline symbols if an outline is applied.” On Mac, go to Excel > Preferences > View and check “Outline symbols.”
  • Grouping is greyed out: This happens if the sheet is protected. Go to Review > Unprotect Sheet (enter password if needed), then try grouping again.
  • Collapsing a group hides the header row: You likely included the header in the grouped range. Ungroup, reselect only the detail rows, and group again.
  • Groups disappear after saving and reopening: This can occur if you saved as an older .xls format. Save as .xlsx to preserve grouping. Also, check that you didn’t accidentally clear the outline.
  • Outline numbers (1,2,3) missing: On Excel for the web, they are not shown. In desktop Excel, they appear only when grouping is applied. If they’re missing, try clicking any plus/minus sign to refresh the outline.

Frequently Asked Questions

  1. Can I group rows and columns at the same time? Yes. Group rows for one section and columns for another. They work independently; you’ll see outline bars on both the left and top.
  2. How do I collapse all groups at once? Click the outline number 1 (top-left area). This collapses all groups to the highest level. To expand all, click the highest number (e.g., 2 or 3).
  3. Can I use expand/collapse without the outline bar? No, the outline bar is the built-in interface. However, you can create a macro with a button to toggle groups—see the VBA example below.
  4. Does grouping work with pivot tables? Pivot tables have their own expand/collapse buttons (plus/minus) for fields. Grouping rows in a pivot table is different; use the pivot table’s native buttons.
  5. Why does my group collapse hide the subtotal row? Because the subtotal is inside the grouped range. Move the subtotal row outside the group (place it directly below the last detail row, but do not select it when grouping).
  6. Can I group non-contiguous rows? Yes, but you must group each contiguous range separately. You cannot select non-adjacent rows and group them as one group.

VBA macro for a custom toggle button (optional): If you want a button to collapse/expand a specific group, use this simple macro. Save a copy of your workbook before running any macro, as macros cannot be undone with Ctrl+Z.

Sub ToggleGroup()
    ' Toggles collapse/expand for rows 2 to 10
    ' Save a copy of the workbook before running
    Dim rng As Range
    Set rng = Rows("2:10")
    If rng.EntireRow.Hidden = True Then
        rng.EntireRow.Hidden = False
    Else
        rng.EntireRow.Hidden = True
    End If
End Sub

To use it, press Alt+F11 to open the VBA editor, insert a new module, paste the code, then assign the macro to a shape or button. This manually hides/shows rows, not the outline, but gives a custom toggle.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.