Function Problems

Excel Formula to Combine the First and Last Names in Each Group

Algirdas JasaitisAlgirdas Jasaitis Nov 22, 2026 869 views

Question details

Create a group name by joining the alphabetically first and last member associated with each compound key.

Combine the First and Last Member Names by Group in Excel
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the data

Select the complete data table, including the headers and any related columns, so each row stays together when sorted.

2
Sort by key and name

Go to Data > Sort. Sort first by Compound Key in ascending order, then add a level to sort by Member Name in ascending order.

3
Enter 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). Adjust row 11 if your data ends on a different row.

4
Fill the formula down

Drag the fill handle from C2 down alongside the remaining data. Each row will display the first and last names for its key.

Sort the Data and Combine the First and Last Matching Names
Keep member names sorted: VLOOKUP returns the first matching row, while LOOKUP returns the last matching row. Sorting member names in ascending order makes those matches the alphabetical endpoints.
WPS Spreadsheet

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. 1. Open the workbook: Open WPS Spreadsheet and select Open to load the workbook containing the compound keys and member names.
  2. 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. 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. 4. Copy the results: Drag the fill handle from C2 down to calculate the group name for each remaining row.
Combine the first and last sorted member names for each compound keyOpen and edit Microsoft Excel XLSX and XLS filesUse familiar spreadsheet sorting and lookup functions
microsoft office alternative - wps office

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.