Private Sub UserForm_Initialize()
ComboBox1.List = Split(" ,1,2,3,4,5", ",")
ComboBox2.List = Split(" ,1,2,3,4,5", ",")
ComboBox3.List = Split(" ,1,2,3,4,5", ",")
ComboBox4.List = Split(" ,1,2,3,4,5", ",")
ComboBox5.List = Split(" ,1,2,3,4,5", ",")
End Sub
Private Sub ComboBox1_Change()
ManageDropDowns (1)
End Sub
Private Sub ComboBox2_Change()
ManageDropDowns (2)
End Sub
Private Sub ComboBox3_Change()
ManageDropDowns (3)
End Sub
Private Sub ComboBox4_Change()
ManageDropDowns (4)
End Sub
Private Sub ComboBox5_Change()
ManageDropDowns (5)
End Sub
Sub ManageDropDowns(IDNum As Integer)
'
' Presuming we have 5 Comboboxes
' This routine ensures there are initially 6 choices for each ComboBox - a blank empty choice and 5 values 1-5
' This will then ensure no 2 ComboBoxes can make the same choice from 1-5 (all can choose blank)
'
Dim UsedList As String, FullList As String, Left2Use As String
Dim FullArray As Variant, UsedArray(1 To 5) As String
UL1 = ""
UL1 = UL1 & IIf(Trim(ComboBox2.Value) = "", "", "" & Trim(ComboBox2.Value) & ",")
UL1 = UL1 & IIf(Trim(ComboBox3.Value) = "", "", "" & Trim(ComboBox3.Value) & ",")
UL1 = UL1 & IIf(Trim(ComboBox4.Value) = "", "", "" & Trim(ComboBox4.Value) & ",")
UL1 = UL1 & IIf(Trim(ComboBox5.Value) = "", "", "" & Trim(ComboBox5.Value) & ",")
While Right(UL1, 1) = ","
UL1 = Left(UL1, Len(UL1) - 1)
Wend
UL2 = ""
UL2 = UL2 & IIf(Trim(ComboBox1.Value) = "", "", "" & Trim(ComboBox1.Value) & ",")
UL2 = UL2 & IIf(Trim(ComboBox3.Value) = "", "", "" & Trim(ComboBox3.Value) & ",")
UL2 = UL2 & IIf(Trim(ComboBox4.Value) = "", "", "" & Trim(ComboBox4.Value) & ",")
UL2 = UL2 & IIf(Trim(ComboBox5.Value) = "", "", "" & Trim(ComboBox5.Value) & ",")
UL3 = ""
UL3 = UL3 & IIf(Trim(ComboBox2.Value) = "", "", "" & Trim(ComboBox2.Value) & ",")
UL3 = UL3 & IIf(Trim(ComboBox1.Value) = "", "", "" & Trim(ComboBox1.Value) & ",")
UL3 = UL3 & IIf(Trim(ComboBox4.Value) = "", "", "" & Trim(ComboBox4.Value) & ",")
UL3 = UL3 & IIf(Trim(ComboBox5.Value) = "", "", "" & Trim(ComboBox5.Value) & ",")
UL4 = ""
UL4 = UL4 & IIf(Trim(ComboBox2.Value) = "", "", "" & Trim(ComboBox2.Value) & ",")
UL4 = UL4 & IIf(Trim(ComboBox3.Value) = "", "", "" & Trim(ComboBox3.Value) & ",")
UL4 = UL4 & IIf(Trim(ComboBox1.Value) = "", "", "" & Trim(ComboBox1.Value) & ",")
UL4 = UL4 & IIf(Trim(ComboBox5.Value) = "", "", "" & Trim(ComboBox5.Value) & ",")
UL5 = ""
UL5 = UL5 & IIf(Trim(ComboBox2.Value) = "", "", "" & Trim(ComboBox2.Value) & ",")
UL5 = UL5 & IIf(Trim(ComboBox3.Value) = "", "", "" & Trim(ComboBox3.Value) & ",")
UL5 = UL5 & IIf(Trim(ComboBox4.Value) = "", "", "" & Trim(ComboBox4.Value) & ",")
UL5 = UL5 & IIf(Trim(ComboBox1.Value) = "", "", "" & Trim(ComboBox1.Value) & ",")
FullList = "1,2,3,4,5"
FullArray = Split(FullList, ",")
Left2Use = " ,"
If IDNum <> 1 Then
UsedList = UL1
Left2Use = " " ' Space
For i = 0 To UBound(FullArray)
iTxt = Trim("" & i + 1)
If Not (InStr(1, UsedList, iTxt) > 0) Then
' Not Already Used - Add it to Left2Use
Left2Use = Left2Use & "," & iTxt
End If
Next i
ComboBox1.List = Split(Left2Use, ",")
End If
If IDNum <> 2 Then
UsedList = UL2
Left2Use = " " ' Space
For i = 0 To UBound(FullArray)
iTxt = Trim("" & i + 1)
If Not (InStr(1, UsedList, iTxt) > 0) Then
' Not Already Used - Add it to Left2Use
Left2Use = Left2Use & "," & iTxt
End If
Next i
ComboBox2.List = Split(Left2Use, ",")
End If
If IDNum <> 3 Then
UsedList = UL3
Left2Use = " " ' Space
For i = 0 To UBound(FullArray)
iTxt = Trim("" & i + 1)
If Not (InStr(1, UsedList, iTxt) > 0) Then
' Not Already Used - Add it to Left2Use
Left2Use = Left2Use & "," & iTxt
End If
Next i
ComboBox3.List = Split(Left2Use, ",")
End If
If IDNum <> 4 Then
UsedList = UL4
Left2Use = " " ' Space
For i = 0 To UBound(FullArray)
iTxt = Trim("" & i + 1)
If Not (InStr(1, UsedList, iTxt) > 0) Then
' Not Already Used - Add it to Left2Use
Left2Use = Left2Use & "," & iTxt
End If
Next i
ComboBox4.List = Split(Left2Use, ",")
End If
If IDNum <> 5 Then
UsedList = UL5
Left2Use = " " ' Space
For i = 0 To UBound(FullArray)
iTxt = Trim("" & i + 1)
If Not (InStr(1, UsedList, iTxt) > 0) Then
' Not Already Used - Add it to Left2Use
Left2Use = Left2Use & "," & iTxt
End If
Next i
ComboBox5.List = Split(Left2Use, ",")
End If
End Sub