Excel Formula to Combine the First and Last Names in Each Group
Question details
Create a group name by joining the alphabetically first and last member associated with each compound key.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet contains compound keys and their associated member names, and the user wants a combined name for each group.
- Observed behavior
- Each result should contain the first and last member names in alphabetical order, separated by a hyphen.
Place compound keys in column A and member names in column B, with headers in row 1. The example uses rows 2 through 11; adjust the formula ranges to cover your data.
Sort the Data and Combine the First and Last Matching Names
Use this method to return a group name on every row for its compound key.
Select the complete data table, including the headers and any related columns, so each row stays together when sorted.
Go to Data > Sort. Sort first by Compound Key in ascending order, then add a level to sort by Member Name in ascending order.
In C2, enter =VLOOKUP(A2,$A$2:$B$11,2,0)&" - "&LOOKUP(2,1/($A$2:$A$11=A2),$B$2:$B$11). Adjust row 11 if your data ends on a different row.
Drag the fill handle from C2 down alongside the remaining data. Each row will display the first and last names for its key.

Combine Group Member Names in WPS Spreadsheet
Sort the key and member columns in WPS Spreadsheet, then use the same lookup formula to create a name for each group.
- 1. Open the workbook: Open WPS Spreadsheet and select Open to load the workbook containing the compound keys and member names.
- 2. Sort the table: Select the full table and use Data > Sort to sort Compound Key in ascending order, then Member Name in ascending order.
- 3. Add the formula: In C2, enter =VLOOKUP(A2,$A$2:$B$11,2,0)&" - "&LOOKUP(2,1/($A$2:$A$11=A2),$B$2:$B$11), adjusting the ranges to match your data.
- 4. Copy the results: Drag the fill handle from C2 down to calculate the group name for each remaining row.

Frequently Asked Questions
Why do I need to sort the member names?
The formula retrieves the first and last matching rows, not the alphabetical endpoints directly. Use Data > Sort to sort by compound key and then by member name in ascending order.
What happens if a group has only one member?
The first and last matches are the same, so the formula displays that member name twice, separated by a hyphen.
How do I use the formula with more than 10 data rows?
Change every range ending in row 11 to your actual last data row. For example, use $A$2:$B$50, $A$2:$A$50, and $B$2:$B$50 for data ending in row 50.
Will the formula show one result per group?
Filled down column C, the formula shows the same group name on every row with the same compound key. It does not create a separate one-row-per-group summary.




