hi
this code works for each three comboboxes dapends on each othere of them for each row on userform . waht I want to change into four comboboxes for each row on userform
here is the code
any help please ?
Option Explicit
Private dic As Object
Dim a, i As Long, ii As Long
Private Sub UserForm_Initialize()
Set dic = CreateObject("Scripting.Dictionary")
a = Sheets("inventory").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
For ii = 1 To UBound(a, 2)
a(i, ii) = a(i, ii) & ""
Next
If Not dic.exists(a(i, 2)) Then
Set dic(a(i, 2)) = CreateObject("Scripting.Dictionary")
End If
If Not dic(a(i, 2)).exists(a(i, 3)) Then
Set dic(a(i, 2))(a(i, 3)) = CreateObject("Scripting.Dictionary")
End If
dic(a(i, 2))(a(i, 3))(a(i, 4)) = Empty
Next
a = mySort(dic.keys)
Me.ComboBox1.List = a
Me.ComboBox4.List = a '**********add this line
Me.ComboBox7.List = a '**********add this line
Me.ComboBox10.List = a '**********add this line
End Sub
Private Sub ComboBox1_Change()
Me.ComboBox2.Clear: Me.ComboBox3.Clear
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox1.Value).keys)
Me.ComboBox2.List = a
End Sub
Private Sub ComboBox4_Change() '*************add this sub
Me.ComboBox5.Clear: Me.ComboBox6.Clear
If Me.ComboBox4.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox4.Value).keys)
Me.ComboBox5.List = a
End Sub
Private Sub ComboBox7_Change() '************add this sub
Me.ComboBox8.Clear: Me.ComboBox9.Clear
If Me.ComboBox7.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox7.Value).keys)
Me.ComboBox8.List = a
End Sub
Private Sub ComboBox10_Change() '***********add this sub
Me.ComboBox11.Clear: Me.ComboBox12.Clear
If Me.ComboBox10.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox10.Value).keys)
Me.ComboBox11.List = a
End Sub
Private Sub ComboBox2_Change()
Me.ComboBox3.Clear
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).keys)
Me.ComboBox3.List = a
End Sub
Private Sub ComboBox5_Change() '***********add this sub
Me.ComboBox6.Clear
If Me.ComboBox5.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox4.Value)(Me.ComboBox5.Value).keys)
Me.ComboBox6.List = a
End Sub
Private Sub ComboBox8_Change() '***********add this sub
Me.ComboBox9.Clear
If Me.ComboBox8.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox7.Value)(Me.ComboBox8.Value).keys)
Me.ComboBox9.List = a
End Sub
Private Sub ComboBox11_Change() '***********add this sub
Me.ComboBox12.Clear
If Me.ComboBox11.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox10.Value)(Me.ComboBox11.Value).keys)
Me.ComboBox12.List = a
End Sub
Function mySort(a)
Dim i As Long, ii As Long, temp
For i = LBound(a) To UBound(a) - 1
For ii = i + 1 To UBound(a)
If a(i) > a(ii) Then
temp = a(i): a(i) = a(ii): a(ii) = temp
End If
Next
Next
mySort = a
End Function
this code works for each three comboboxes dapends on each othere of them for each row on userform . waht I want to change into four comboboxes for each row on userform
here is the code
VBA Code:
Option Explicit
Private dic As Object
Dim a, i As Long, ii As Long
Private Sub UserForm_Initialize()
Set dic = CreateObject("Scripting.Dictionary")
a = Sheets("inventory").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
For ii = 1 To UBound(a, 2)
a(i, ii) = a(i, ii) & ""
Next
If Not dic.exists(a(i, 2)) Then
Set dic(a(i, 2)) = CreateObject("Scripting.Dictionary")
End If
If Not dic(a(i, 2)).exists(a(i, 3)) Then
Set dic(a(i, 2))(a(i, 3)) = CreateObject("Scripting.Dictionary")
End If
dic(a(i, 2))(a(i, 3))(a(i, 4)) = Empty
Next
a = mySort(dic.keys)
Me.ComboBox1.List = a
Me.ComboBox4.List = a '**********add this line
Me.ComboBox7.List = a '**********add this line
Me.ComboBox10.List = a '**********add this line
End Sub
Private Sub ComboBox1_Change()
Me.ComboBox2.Clear: Me.ComboBox3.Clear
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox1.Value).keys)
Me.ComboBox2.List = a
End Sub
Private Sub ComboBox4_Change() '*************add this sub
Me.ComboBox5.Clear: Me.ComboBox6.Clear
If Me.ComboBox4.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox4.Value).keys)
Me.ComboBox5.List = a
End Sub
Private Sub ComboBox7_Change() '************add this sub
Me.ComboBox8.Clear: Me.ComboBox9.Clear
If Me.ComboBox7.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox7.Value).keys)
Me.ComboBox8.List = a
End Sub
Private Sub ComboBox10_Change() '***********add this sub
Me.ComboBox11.Clear: Me.ComboBox12.Clear
If Me.ComboBox10.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox10.Value).keys)
Me.ComboBox11.List = a
End Sub
Private Sub ComboBox2_Change()
Me.ComboBox3.Clear
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).keys)
Me.ComboBox3.List = a
End Sub
Private Sub ComboBox5_Change() '***********add this sub
Me.ComboBox6.Clear
If Me.ComboBox5.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox4.Value)(Me.ComboBox5.Value).keys)
Me.ComboBox6.List = a
End Sub
Private Sub ComboBox8_Change() '***********add this sub
Me.ComboBox9.Clear
If Me.ComboBox8.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox7.Value)(Me.ComboBox8.Value).keys)
Me.ComboBox9.List = a
End Sub
Private Sub ComboBox11_Change() '***********add this sub
Me.ComboBox12.Clear
If Me.ComboBox11.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox10.Value)(Me.ComboBox11.Value).keys)
Me.ComboBox12.List = a
End Sub
Function mySort(a)
Dim i As Long, ii As Long, temp
For i = LBound(a) To UBound(a) - 1
For ii = i + 1 To UBound(a)
If a(i) > a(ii) Then
temp = a(i): a(i) = a(ii): a(ii) = temp
End If
Next
Next
mySort = a
End Function
Option Explicit
Private dic As Object
Dim a, i As Long, ii As Long
Private Sub UserForm_Initialize()
Set dic = CreateObject("Scripting.Dictionary")
a = Sheets("inventory").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
For ii = 1 To UBound(a, 2)
a(i, ii) = a(i, ii) & ""
Next
If Not dic.exists(a(i, 2)) Then
Set dic(a(i, 2)) = CreateObject("Scripting.Dictionary")
End If
If Not dic(a(i, 2)).exists(a(i, 3)) Then
Set dic(a(i, 2))(a(i, 3)) = CreateObject("Scripting.Dictionary")
End If
dic(a(i, 2))(a(i, 3))(a(i, 4)) = Empty
Next
a = mySort(dic.keys)
Me.ComboBox1.List = a
Me.ComboBox4.List = a '**********add this line
Me.ComboBox7.List = a '**********add this line
Me.ComboBox10.List = a '**********add this line
End Sub
Private Sub ComboBox1_Change()
Me.ComboBox2.Clear: Me.ComboBox3.Clear
If Me.ComboBox1.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox1.Value).keys)
Me.ComboBox2.List = a
End Sub
Private Sub ComboBox4_Change() '*************add this sub
Me.ComboBox5.Clear: Me.ComboBox6.Clear
If Me.ComboBox4.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox4.Value).keys)
Me.ComboBox5.List = a
End Sub
Private Sub ComboBox7_Change() '************add this sub
Me.ComboBox8.Clear: Me.ComboBox9.Clear
If Me.ComboBox7.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox7.Value).keys)
Me.ComboBox8.List = a
End Sub
Private Sub ComboBox10_Change() '***********add this sub
Me.ComboBox11.Clear: Me.ComboBox12.Clear
If Me.ComboBox10.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox10.Value).keys)
Me.ComboBox11.List = a
End Sub
Private Sub ComboBox2_Change()
Me.ComboBox3.Clear
If Me.ComboBox2.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox1.Value)(Me.ComboBox2.Value).keys)
Me.ComboBox3.List = a
End Sub
Private Sub ComboBox5_Change() '***********add this sub
Me.ComboBox6.Clear
If Me.ComboBox5.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox4.Value)(Me.ComboBox5.Value).keys)
Me.ComboBox6.List = a
End Sub
Private Sub ComboBox8_Change() '***********add this sub
Me.ComboBox9.Clear
If Me.ComboBox8.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox7.Value)(Me.ComboBox8.Value).keys)
Me.ComboBox9.List = a
End Sub
Private Sub ComboBox11_Change() '***********add this sub
Me.ComboBox12.Clear
If Me.ComboBox11.ListIndex = -1 Then Exit Sub
a = mySort(dic(Me.ComboBox10.Value)(Me.ComboBox11.Value).keys)
Me.ComboBox12.List = a
End Sub
Function mySort(a)
Dim i As Long, ii As Long, temp
For i = LBound(a) To UBound(a) - 1
For ii = i + 1 To UBound(a)
If a(i) > a(ii) Then
temp = a(i): a(i) = a(ii): a(ii) = temp
End If
Next
Next
mySort = a
End Function