abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,494
- Office Version
- 2019
- 2010
- Platform
- Windows
hello
i got this code from this link
VBA Combobox options to be filtered by three other comboboxes
I try amending to show all of columns in listbox but I failed so my data in sheet begins from a2: e and the code populate column a,b,c
I would truly appreciate if anybody help
i got this code from this link
VBA Combobox options to be filtered by three other comboboxes
I try amending to show all of columns in listbox but I failed so my data in sheet begins from a2: e and the code populate column a,b,c
VBA Code:
Private Sub UserForm_Initialize()
Dim Ary As Variant, x As Variant
Dim i As Long
Set UfDic = CreateObject("scripting.dictionary")
With Sheets("codes")
Ary = .Range("A2:e" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
End With
For i = 1 To UBound(Ary)
If Not UfDic.Exists(Ary(i, 1)) Then UfDic.Add Ary(i, 1), CreateObject("scripting.dictionary")
If Not UfDic(Ary(i, 1)).Exists(Ary(i, 2)) Then UfDic(Ary(i, 1)).Add Ary(i, 2), CreateObject("scripting.dictionary")
If Not UfDic(Ary(i, 1))(Ary(i, 2)).Exists(Ary(i, 3)) Then UfDic(Ary(i, 1))(Ary(i, 2)).Add Ary(i, 3), CreateObject("scripting.dictionary")
If Not UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3)).Exists(Ary(i, 4)) Then
UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3)).Add Ary(i, 4), Application.Transpose(Array(Ary(i, 1), Ary(i, 2), Ary(i, 3), (Ary(i, 4)), (Ary(i, 5))))
Else
x = UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3))(Ary(i, 4))
ReDim Preserve x(1 To 5, 1 To UBound(x, 2) + 1)
x(1, UBound(x, 2)) = Ary(i, 1)
x(2, UBound(x, 2)) = Ary(i, 2)
x(3, UBound(x, 2)) = Ary(i, 3)
x(4, UBound(x, 2)) = Ary(i, 4)
x(5, UBound(x, 2)) = Ary(i, 5)
UfDic(Ary(i, 1))(Ary(i, 2))(Ary(i, 3))(Ary(i, 4)) = x
End If
Next i
Me.ComboBox1.List = UfDic.Keys
End Sub