Hello all,
I am having trouble with some code to populate one User Form list box based on the values in another. The user has a list of available colors on the left and uses command buttons to either
1) Add All
2) Add Selected
3) Remove Selected
4) Remove All
The Add All and Remove All functions are working but the Add/Removed selected is not.
My code for Add Selected:
Private Sub CmdBtn_AddColor_Click()
'
'Source: Move user selected values from list box 1 to list box 2: https://analysistabs.com/excel-vba/listbox-adding-clearing-items-multiple-selection/
'
Dim iCnt As Integer
For iCnt = 0 To Me.LstBx_ColorsSelected.ListCount - 1
If Me.LstBx_ColorsSelected.Selected(iCnt) = True Then
Me.LstBx_ColorsAvailable.AddItem Me.LstBx_ColorsSelected.List(iCnt)
End If
Next
For iCnt = Me.LstBx_ColorsSelected.ListCount - 1 To 0 Step -1
If Me.LstBx_ColorsSelected.Selected(iCnt) = True Then
Me.LstBx_ColorsSelected.RemoveItem iCnt
End If
Next
End Sub
My code for Remove Selected, this function simply needs to remove the selected items from the list box, it does not need to repopulate them back to the other list box.
Private Sub CmdBtn_RemoveColor_Click()
'
'Source: Move user selected values from list box 1 to list box 2: https://analysistabs.com/excel-vba/listbox-adding-clearing-items-multiple-selection/
'
Dim iCnt As Integer
For iCnt = 0 To Me.LstBx_ColorsSelected.ListCount - 1
If Me.LstBx_ColorsSelected.Selected(iCnt) = True Then
Me.LstBx_ColorsSelected.RemoveItem
End If
End Sub
A copy of my project is attached. I have not yet written code for the other functions of the User Form.
Bookmarks