Grouping cells in Excel for sorting means two different things depending on your goal. If you want to sort records while keeping each row's data together, the answer is to convert your data into a single Excel Table (Select the range, then Insert > Table) so every row moves as one unit. If you want to sort by category using collapsible groups, the answer is to sort first and then apply Data > Group from the Outline tools, or use a PivotTable so Excel does the grouping for you. Either way, the one thing that breaks sorting more than anything else is a blank row or column inside your data, so clean that up before you start.

What You'll Need

  • Excel for Windows, Mac, or Excel for the web. Menu labels can differ slightly by version, device, and region, so if a name doesn't match exactly, look for the closest equivalent.
  • Source data with a single header row and no merged cells.
  • No blank rows or blank columns inside the range you want to sort.
  • Consistent data types in each column (all numbers, all dates, or all text) so the sort order behaves predictably.
  • A backup copy of the sheet if you're working with anything important, since sorting cannot be undone after you save and close.

Step-by-Step

Method 1: Keep rows together with a Table

  1. Click any single cell inside your data. Don't select the whole sheet.
  2. Go to Insert > Table. Confirm the range Excel highlights and that My table has headers is ticked, then click OK.
  3. Click the drop-down arrow on any column header in the Table and choose Sort A to Z, Sort Z to A, or pick a custom order.
  4. Every row moves as a complete record, so a name stays with its address, phone number, and order date. This is the behaviour most people actually want when they say "group cells for sorting."
  5. To sort by more than one level, use Data > Sort and add levels with Add Level. Put the highest-priority column first, then the tie-breaker second (for example, Department first, then Last Name).

Method 2: Sort plain ranges safely

  1. Select the entire range including headers, or click one cell and let Excel guess the region. A single click inside a well-formed block is usually enough.
  2. Go to Data > Sort. Tick My data has headers so the header row stays at the top.
  3. Choose the Sort by column, the Sort On value (Cell Values, Cell Color, Font Color, or Conditional Formatting Icon), and the Order (A to Z, Z to A, or Custom List).
  4. Click OK. Excel expands your selection to the surrounding block automatically, which is why blank rows and columns must not exist.

Method 3: Collapsible groups with the Outline tools

  1. If you want to collapse and expand sections rather than reorder rows, select the rows or columns you want to group.
  2. Go to Data > Group under the Outline section. Excel adds a bracket and a plus/minus button in the margin.
  3. Use Data > Subtotal first if you want grouped headers with subtotals. Subtotals are what create the data hierarchy Excel can group cleanly, so sort your category column before running it.
  4. Click the numbered buttons at the top-left of the outline (1, 2, 3) to collapse or expand all levels at once.
  5. To remove grouping, select the grouped rows and use Data > Ungroup.

Method 4: Group without touching the layout using a PivotTable

  1. Click inside your data and choose Insert > PivotTable.
  2. Drag your category field into the Rows area. The PivotTable automatically consolidates duplicates into groups.
  3. Drag a numeric field into Values to see counts or sums per group.
  4. Right-click any date or number in a row label and choose Group to combine values into ranges or date periods. This is the cleanest way to group for reporting without disturbing your source data.

Common Mistakes

  • Sorting only one column. If you select a single column and hit Sort, Excel asks whether to expand the selection. Choosing Continue with the current selection scatters rows and destroys your records. Always pick Expand the selection.
  • Merged cells in the header. Merged headers confuse Excel's range detection. Unmerge them first, put the label in one cell, and leave the rest blank.
  • Blank rows splitting your data. Excel treats a blank row as the end of the block. The rows below it stay unsorted, which looks like a partial sort failure.
  • Numbers stored as text. Text numbers sort left-to-right by character (so 10 comes before 2). Use Data > Text to Columns or multiply by 1 to convert them.
  • Trailing spaces. "Sales " and "Sales" become two separate groups. Run Find & Replace with a space in the find box and an empty replace box to clean them up.
  • Expecting Group to sort for you. Data > Group builds collapsible outlines; it does not rearrange rows. Sort first, then group.

Tips

  • Freeze the header row with View > Freeze Panes so labels stay visible while you review the sorted result.
  • Use Custom Lists under Data > Sort > Order to sort Monday-to-Sunday or Low-Medium-High instead of alphabetical order.
  • Sort by cell colour or icon if you've applied conditional formatting, which lets you group visually flagged items at the top.
  • Add a helper column with a formula such as =TRIM(A2) if inconsistent spacing keeps splitting your groups, then sort on the helper column.
  • When sorting by multiple levels, always put unique columns in the final level so ties resolve predictably.
  • Keep a copy of the original order in a numbered column if you may need to restore it later.

Troubleshooting

If the sort does nothing, check whether the sheet is protected (Review > Unprotect Sheet) or whether a filter is hiding rows. If only part of your data moved, a blank row or column is almost certainly splitting the block, so delete it and try again. If Excel warns about expanding the selection, always accept it unless you genuinely want to sort a standalone list.

If groups collapse into odd hierarchies after using Subtotal, your data probably wasn't sorted by the category column first. Remove the subtotals with Data > Subtotal > Remove All, sort properly, then reapply. If the Group button is greyed out, you're likely inside a PivotTable or a protected area, where grouping works through the PivotTable right-click menu rather than the ribbon.

If dates group into single days when you wanted months, right-click a date row label in the PivotTable and choose Group, then select Months or Quarters. If the sorted order still looks wrong, inspect for hidden characters and inconsistent data types in the column; cleaning the source is faster than re-sorting repeatedly.

Frequently Asked Questions

Does grouping cells make Excel sort them?

No. Data > Group creates collapsible outline sections. Sorting is a separate action, so sort your rows first and then group them if you want both.

How do I sort while keeping rows together?

Click one cell inside the data and use Data > Sort with My data has headers ticked, or convert the range to a Table. Either way, Excel expands the selection to the whole row.

Why did only one column sort?

You selected a single column before sorting and chose to keep the current selection. Undo with Ctrl+Z (Cmd+Z on Mac), then re-sort with the full range selected.

Can I group rows by category and sort within each group?

Yes. Sort by the category column first, then add a second sort level for the within-group order. After that, use Data > Group or a PivotTable to display it as groups.

What is the keyboard shortcut to sort?

Select your data and press Alt, then A, then S, then S in Windows Excel to open the Sort dialog. Mac users can use the Data menu instead.

Does grouping work in Excel for the web?

Tables and sorting work there, but some outline and PivotTable grouping options are limited compared with the desktop app. If a button is missing, open the file in the desktop version.