Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
I have two listboxes and 32 comboboxes each containing the same information and that is a list of peoples names. The subroutine "toPopulate" populates the listboxes and comboboxes. The first listbox "listbox1" is for PTO and the second is for vacation. This is for a schedule maker and based on who is scheduled off their name will be removed from the second listbox "listbox2" and all 32 comboboxes, combobox1--->combobox32. The code below this one works but when it loops again, it does not remove the second and other selections that are made. Thank you.
VBA Code:
Sub toPopulate(n As Long)
Dim i As Long, l As Long
Dim tx As String
Dim X
d.RemoveAll
e.RemoveAll
For i = 1 To 32
tx = UserForm1.Controls("ComboBox" & i).Text
If tx <> "" And i <> n Then e(tx) = Empty
Next
If e.Count <> 0 Then
For Each X In va
If Not e.Exists(X) Then d(X) = Empty
Next
Else
For Each X In va
d(X) = Empty
Next
End If
UserForm1.Controls("ComboBox" & n).List = d.keys
UserForm1.Controls("ListBox" & n).List = d.keys
End Sub
VBA Code:
Private Sub ListBox1_Change()
Dim index As Integer
Dim cell As Range
For index = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.Selected(index) = True Then
MsgBox Me.ListBox1.List(index)
End If
'Ensure ListBox contains list items
If ListBox1.ListCount >= 1 Then
'If no selection, choose last list item.
If ListBox1.ListIndex = -1 Then
ListBox1.ListIndex = ListBox1.ListCount - 1
End If
End If
Next
ListBox2.RemoveItem (ListBox1.ListIndex)
ComboBox1.RemoveItem (ListBox1.ListIndex)
End Sub