Populate an Excel VBA Team List Box from Multiple List Boxes
Question details
Combine a selected role and person in a team list box and remove both entries from their original lists.

- Product
- Microsoft Excel VBA UserForm
- Device & OS
- not provided
- Scenario
- A UserForm has separate role and name list boxes and a team list box for assignments.
- Observed behavior
- The desired result is a team list containing each selected role and name, with assigned entries removed from the source lists to prevent duplicate assignments.
Open the workbook in desktop Excel and make sure it is saved as a macro-enabled workbook (.xlsm). The example uses single-selection, unbound UserForm list boxes; clear their RowSource properties if they are set.
Add Selected Roles and Names to a Two-Column Team List Box
Use a UserForm button to validate selections, add the pair to the team list, and remove the original entries.
In desktop Excel, select Developer > Visual Basic. In the VBA editor, open the UserForm that contains the list boxes.
In the Properties window, name the source list boxes lstRole and lstName, the destination list box lstTeam, and the command button cmdAdd. Set lstRole and lstName to single selection and set lstTeam's ColumnCount property to 2.
Double-click cmdAdd and replace its Click procedure with this code: Private Sub cmdAdd_Click() Dim roleIndex As Long, nameIndex As Long Dim roleText As String, nameText As String Dim teamRow As Long If lstRole.ListCount = 0 Or lstName.ListCount = 0 Then MsgBox "Both source lists must contain items." Exit Sub End If roleIndex = lstRole.ListIndex nameIndex = lstName.ListIndex If roleIndex = -1 Or nameIndex = -1 Then MsgBox "Select a role and a name first." Exit Sub End If roleText = lstRole.List(roleIndex, 0) nameText = lstName.List(nameIndex, 0) lstTeam.AddItem roleText teamRow = lstTeam.ListCount - 1 lstTeam.List(teamRow, 1) = nameText lstRole.RemoveItem roleIndex lstName.RemoveItem nameIndex End Sub
Run the UserForm, select one role and one name, and click the Add button. Confirm that the pair appears in lstTeam and that both source entries disappear.

Manage Team Assignment Spreadsheets with WPS Office
WPS Office is a free, lightweight alternative for working with team assignment spreadsheets in a familiar interface. Open compatible Excel files to move your spreadsheet work across, but test VBA macros and UserForms separately because they may not work the same way as in Excel.

Frequently Asked Questions
Why does the button ask me to select a role and a name?
The code checks each source list box's ListIndex. Select one entry in both lstRole and lstName before clicking cmdAdd.
Why does RemoveItem fail on my list box?
The list box may be bound to a worksheet range through its RowSource property. Clear RowSource and populate the list in VBA, or update the underlying range instead.
How can I return a team assignment to the original lists?
On a separate button, read the selected lstTeam row with lstTeam.List(lstTeam.ListIndex, 0) and lstTeam.List(lstTeam.ListIndex, 1). Add those values back to lstRole and lstName with AddItem, then remove the selected team row. Check that lstTeam.ListIndex is not -1 first.
How do I keep the team list values in separate columns?
Set lstTeam's ColumnCount property to 2 in the VBA editor. Add the role with AddItem, then assign the name to column 1 of the new row using the List property.




