Sort Families Alphabetically in Excel While Keeping Members Together
Question details
Sort a list of families alphabetically while keeping all members of each family 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.
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.
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.
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.
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.
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.
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 Family ID When Alphabetical Family Order Is Not Required
Use this simpler option to group members by ID and alphabetize names within each group.
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. 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. 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. Paste the keys as values: Copy the Family Sort Key cells, then use Paste Special > Values to replace the formulas with fixed keys.
- 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. 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.

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.




