Function Problems

Sort Families Alphabetically in Excel While Keeping Members Together

John WilsonJohn Wilson Nov 18, 2026 870 views

Question details

Sort a list of families alphabetically while keeping all members of each family together.

Sort Families Alphabetically in Excel While Keeping Members Together
Product
Microsoft Excel
Device & OS
not provided
Scenario
Each family has a shared Family ID, but members of the same family may have different last names.
Observed behavior
The desired result is an alphabetical list of family groups, with every member remaining in the correct group.
Before you start

Check that every member of a family has the same Family ID and that the first occurrence of each ID has the last name you want to use for that family’s alphabetical position. The example below assumes Family ID is in column A, Last Name is in column B, and row 1 contains headers.

Solution 1Recommended

Sort by a Family Name Key and Family ID

Use the first listed last name for each Family ID as a shared alphabetical key, even when family members have different last names.

1
Add a sort key

Insert a blank column in the table and name it Family Sort Key. In its first data cell, enter =VLOOKUP(A2,$A$2:$B$100,2,FALSE). Change 100 to the last data row, then fill the formula down.

2
Fix the key values

Select the calculated Family Sort Key cells, copy them, and use Home > Paste > Values to replace the formulas with their results. This keeps the keys from changing when rows are reordered.

3
Open the sort dialog

Select the entire table, including all member columns and the new key, then go to Data > Sort. Check My data has headers if it is available.

4
Set the sort levels

Sort first by Family Sort Key from A to Z. Use Add Level to sort next by Family ID, then add Last Name from A to Z if you also want names sorted within each family. Click OK.

Sort by a Family Name Key and Family ID
Why include Family ID?: The Family ID level keeps different families separate when they share the same sort key. The key uses the first matching last name, not necessarily every member’s last name.
Sort family lists in WPS Spreadsheet

Keep Families Together While Sorting in WPS Spreadsheet

Use a shared family-name key and a multilevel sort in WPS Spreadsheet to arrange family groups alphabetically without separating members.

  1. 1. Open the list: Open your workbook in WPS Spreadsheet. Confirm that Family ID is in column A and Last Name is in column B, with headers in row 1.
  2. 2. Create a family key: Add a Family Sort Key column. In its first data cell, enter =VLOOKUP(A2,$A$2:$B$100,2,FALSE), adjusting 100 to the last data row, and fill the formula down.
  3. 3. Paste the keys as values: Copy the Family Sort Key cells, then use Paste Special > Values to replace the formulas with fixed keys.
  4. 4. Sort the complete table: Select the whole table and open Data > Sort. Set Family Sort Key as the first ascending level and Family ID as the second; add Last Name as a third level if desired.
  5. 5. Apply and save: Click OK to apply the sort, check that each family remains together, and use File > Save or Save As to save the workbook.
Group members with different last names under the same Family IDSort families alphabetically using a shared family-name keyOpen and save Microsoft Excel XLSX and XLS filesUse familiar spreadsheet formulas and sorting controls
microsoft office alternative - wps office

Frequently Asked Questions

Why not just sort the Last Name column?

Members of one family can have different last names, so sorting only by Last Name can separate them. Use a shared Family Sort Key followed by Family ID in Data > Sort.

Which name does the VLOOKUP formula use for a family?

The exact-match VLOOKUP uses the last name on the first row where it finds that Family ID. Make sure that row contains the name you want to use for the family’s alphabetical position.

What if two families have the same family sort key?

Add Family ID as the second level in Data > Sort. This keeps the two families in separate groups even when their keys match.

Why should I paste the sort keys as values?

The formula looks up the first matching ID in the list. Pasting the results as values before sorting prevents the key from changing when the row order changes.