To group rows that share a name, first sort the entire data range by the Name column so identical names sit together. For collapsible groups without extra totals, select each matching block by its row numbers and choose Data > Outline > Group. If you also want a count or sum for each name, use Data > Outline > Subtotal instead; Excel creates the groups as it inserts subtotal rows.
Excel groups adjacent rows, not every matching value wherever it appears. Sorting is therefore essential when names are scattered through the list. The instructions below are for Excel for Microsoft 365 on Windows, with notes for other versions.
What You’ll Need
- A worksheet with a header row and one row per record, including a column containing the names you want to group.
- If you want automatic subtotals, a numeric column to total or count. Save a copy first if you are unsure whether you want Excel to add subtotal rows to your data.
- Desktop Excel for the full Subtotal workflow. Excel for the web may show existing outlines, but use the desktop app if the Subtotal command is unavailable.
Step-by-Step
- Check the data layout. Keep one set of column headings at the top, with no completely blank rows or columns splitting the list. Make sure each record is on one row and the name column contains the values you intend to group. For instance, entries such as Alex, Jordan, Alex will not form one continuous Alex block until you sort them. If there are extra spaces or inconsistent spellings, correct them first: Excel treats Alex, Alex with a trailing space, and ALEX as potentially different text values when grouping or sorting.
- Select and sort the whole data range by name. Select the complete list, including all columns for each record and the header row. On the Data tab, choose Sort. In the Sort dialog, tick My data has headers if it is not already selected, set Sort by to the name column, and choose A to Z (or Z to A). Click OK. Sorting only the name column can detach names from their related information, so always sort the complete range. If Excel asks whether to expand the selection, choose Expand the selection. If the records are formatted as an Excel table, clicking a cell in the Name column and using its filter arrow to sort is also suitable because the table keeps the columns together.
- Choose the kind of grouping you want. Use manual grouping if you only want to collapse and expand matching rows without adding calculations or changing the data with subtotal lines. Use Subtotal if each name should have an inserted summary row, such as a sum of sales or a count of records. These are different outcomes: a manual outline only hides or displays rows, while Subtotal adds summary rows and an outline.
- For manual groups, select the first name block by row numbers. Find the first continuous block after sorting. Click the row number of its first detail row, then drag down the row-number margin to its last detail row. Select the whole rows using the row headers at the left, not just the cells in the Name column. Leave the worksheet’s column-heading row outside the selection. If there are two Alex records in rows 2 and 3, for example, select row headers 2 and 3.
- Create the manual outline. Choose Data > Outline > Group, then choose Rows if Excel presents a choice. A bracket and a minus button should appear beside the selected rows. Click the minus button to collapse that block; click the plus button to show it again. Repeat the selection and grouping for each other name block that you want to control separately. Do not select the entire sorted list as one group if the aim is to collapse each name independently; that would hide all those records together.
- For automatic groups with totals, open Subtotal. Click a cell in the sorted range, then choose Data > Outline > Subtotal. In the dialog, set At each change in to the name column. Select a calculation under Use function, such as Sum or Count, then tick the numeric or name column to which the calculation should apply under Add subtotal to. For example, to total sales by name, choose Sum and tick Sales. Keep Summary below data selected if you want each summary line beneath its group. Click OK. Excel inserts a subtotal row at each change of name and adds outline controls at the left.
- Use the outline controls to see the view you need. In an automatic subtotal outline, the numbered level buttons above the row numbers show different levels of detail. The most detailed level displays every record; a less detailed level hides records and leaves summaries; the top level shows only the overall result. The plus and minus buttons expand or collapse individual groups. Manual groups use plus and minus controls too, although they do not have subtotal lines. If the controls are not obvious, check the left edge of the row headers and make sure outline symbols are enabled in Excel’s display options.
- Verify that each group contains the intended records. Expand a few groups and compare their names with the source rows. For Subtotal, check a summary against a quick selection or a known total. Save the workbook after checking. Manual groups are a view of the existing rows, but Subtotal inserts rows into the list; be careful if other formulas, charts, or processes expect the data to be one uninterrupted block.
To undo automatic subtotals: choose Data > Outline > Subtotal and click Remove All. This removes the inserted subtotal rows and outline, but does not restore an earlier sort order. To remove a manual group, select its grouped row headers and choose Data > Outline > Ungroup. If several groups are selected, check the selection before ungrouping so you do not remove more outline structure than intended.
Common Mistakes
- Grouping before sorting: Excel groups a continuous range of rows. If the same name appears in separate parts of the sheet, those records will not become one group just because their text matches. Sort the whole range first, then group each resulting block.
- Sorting only one column: This can put a name beside another person’s sales, dates, or notes. Select the full data range, confirm Expand the selection if prompted, and check that every row’s fields stayed together.
- Selecting cells instead of entire rows: A cell selection may still allow an outline, but it is easier to select the wrong extent or include uneven columns. Use the row-number headers for manual row groups, and select only the records belonging to that name.
- Using Subtotal on an Excel table: The Subtotal command may be disabled for a formatted table. You can use manual grouping, or convert a copy of the table to a range using Table Design > Tools > Convert to Range, then use Subtotal. Converting removes table behavior such as automatic expansion and structured references, so do not do it casually.
- Choosing the wrong subtotal field or function: Sum is appropriate for numeric amounts, while Count counts nonblank entries in the selected field. Selecting a text-only column for Sum will not total amounts. Review the dialog selections before clicking OK.
- Expecting a live, permanent grouping rule: An outline is not a rule that continuously watches names. New rows may fall outside existing groups, and changing a name can leave a row in the wrong block. Re-sort and update the outline after making substantial data changes.
Tips
- Turn the range into a table before routine sorting and filtering if you want new records to inherit formatting and table features. You can still sort the whole table by the name column. Remember that the table itself is not the same thing as a collapsible outline.
- For a useful summary, pick the measure before running Subtotal. Sum sales or hours, or use Count on a reliably filled field such as an order ID. A count of names tells you how many nonblank name entries are in each block, not how many different names exist.
- Use A to Z for a predictable order, and inspect the first and last few rows of each block if names include unusual spacing, punctuation, or spelling variants. Find and Replace can help correct consistent errors, but inspect replacements before applying them broadly.
- Keep a clean source copy if you need to reuse the data for a PivotTable, import, or other analysis. Subtotal rows are useful for a report, but they are extra rows and can interfere with tools that expect every row to be a record.
- For a long list, use the outline level buttons to switch between detail and summary views instead of collapsing groups one by one. You can expand a single section later when you need to inspect its records.
Troubleshooting
The Group or Subtotal command is unavailable: Check whether the sheet is protected, whether you are editing a cell, or whether the data is an Excel table. Exit cell editing with Enter or Esc, unprotect the sheet if you have permission, and try again. For Subtotal on a table, work on a copy converted to a range or use manual grouping.
Some matching names are in different groups: The rows may not be adjacent, or the values may not actually match. Sort the complete range again, then inspect spaces and spelling. A blank row can also make the list feel split; remove it if it is not intentional, or treat the sections as separate data ranges.
The wrong rows collapse: Expand the group, inspect the row-number range, and ungroup it. Then select only the correct contiguous rows by their row headers and group again. If you used Subtotal and the grouping is broadly wrong, use Remove All, correct the sort or name data, and run Subtotal again.
The plus and minus controls are missing: Look for outline symbols beside the row numbers. In Windows Excel, open File > Options > Advanced and, under Display options for this worksheet, enable Show outline symbols if an outline is applied. On Mac, check Excel > Preferences (or Settings, depending on the release) for the worksheet display options. If you are in Excel for the web and cannot create or change the outline, open the workbook in desktop Excel.
Subtotal totals do not look right: Confirm that you sorted by the same field selected in At each change in, and that the chosen calculation and field are correct. Check that the amounts are numeric rather than numbers stored as text, and look for blank or inconsistent entries. Remove the subtotals, fix the source values, and run the operation again if needed.
Frequently Asked Questions
Can Excel group rows with the same name automatically?
Yes. Sort the full range by name, then run Data > Outline > Subtotal and set At each change in to the name field. Excel creates an outline and summary rows. For collapsible blocks without summary rows, create manual groups after sorting.
Can I group matching names without adding subtotal rows?
Yes. Sort the whole list by name, select the rows for one continuous name block using their row numbers, and choose Data > Outline > Group. Repeat for each block. This hides and shows rows but does not calculate or insert a total.
Can one name have more than one group?
It can, if the rows are separated or you select only part of a name’s records. Sort first and group the full continuous block for that name if you want one control. Subtotal makes a group at each change in the selected field, so inconsistent spellings can create separate groups.
Will new rows automatically join the right group?
Not reliably. An outline does not automatically re-sort new records or recalculate group boundaries as a rule. Add the records, sort the full range again, and rebuild or adjust the groups when necessary.
Does grouping hide or delete the rows?
No. Collapsing a group hides its detail rows from view; it does not delete them. Click the plus control to show them again. Subtotal does insert summary rows, so use Remove All if you want to remove those summaries and their outline.
Can I do this in Excel for Mac or the web?
Excel for Mac has sorting and row-outline features, although ribbon labels or settings locations can vary by release. The Data > Subtotal workflow is most dependable in desktop Excel. Excel for the web may display an existing outline; if the commands you need are missing, choose Open in Desktop App.
Related
- Excel MODE.MULT: Find Multiple Modes in a Data Set
- Excel Days, Hours, and Minutes: Format Durations
- Excel Day School? Meaning and How to Identify One
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Power Query: Select Columns and Keep the Fields You NeedTo select columns in Power Query for Excel, open the query in Power Query Editor, then choose Home…
- Excel Columns Keep Collapsing? Causes and FixesIf Excel columns keep collapsing, they are usually hidden or grouped into an outline—not deleted. On Windows, select…
- Excel Decrease Decimal Shortcut: Steps, Mac, and FixesIn Excel for Microsoft 365 on Windows, select the cell or cells and press Alt, H, 9 to…
- Insert Row in Excel: Keyboard Shortcut for WindowsTo insert a worksheet row in Excel for Microsoft 365 on Windows, select the row where the new…
- Absolute Cell Reference Excel Shortcut: F4 ExplainedIn Excel for Microsoft 365 on Windows, press F4 while editing a formula and the insertion point is…
- How to Combine Cells in Excel and Keep TextTo combine the text from cells without losing anything, enter a formula such as =A2&" "&B2 in an…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.