abdo meghari
Active Member
- Joined
- Aug 3, 2021
- Messages
- 465
- Office Version
- 2019
hi
I need updating this code . currently filter data based on names in combobox1 linked with col G . now I would add two comboboxes (combobox2= month, combobox3= year) . the month in combobox2 should be 1,2... etc and combobox 3 = 2021 they are both linked with COL D is date (dd/mm/yyyy) . so three comboboxes should link for each other of them
I need updating this code . currently filter data based on names in combobox1 linked with col G . now I would add two comboboxes (combobox2= month, combobox3= year) . the month in combobox2 should be 1,2... etc and combobox 3 = 2021 they are both linked with COL D is date (dd/mm/yyyy) . so three comboboxes should link for each other of them
VBA Code:
Private Sub ComboBox1_Change()
Dim f As Range, r As Range, cell As String
ListBox1.Clear
If ComboBox1.Value = "" Or ComboBox1.ListIndex = -1 Then Exit Sub
Set r = sh.Range("g4:g" & sh.Range("G" & Rows.Count).End(xlUp).Row)
Set f = r.Find(ComboBox1.Value, , xlValues, xlWhole)
If Not f Is Nothing Then
cell = f.Address
Do
With ListBox1
.AddItem sh.Range("A" & f.Row).Value
.List(.ListCount - 1, 1) = sh.Range("B" & f.Row).Value 'Data from Col B
.List(.ListCount - 1, 2) = sh.Range("C" & f.Row).Value 'Data from Col C
.List(.ListCount - 1, 3) = sh.Range("D" & f.Row).Value 'Data from Col D
.List(.ListCount - 1, 4) = sh.Range("E" & f.Row).Value 'Data from Col E
.List(.ListCount - 1, 5) = sh.Range("F" & f.Row).Value 'Data from Col f
.List(.ListCount - 1, 6) = sh.Range("G" & f.Row).Value 'Data from Col g
End With
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
End If
End Sub
Private Sub UserForm_Initialize()
Dim i As Long, dic As Object
Set sh = Sheet3
Set dic = CreateObject("Scripting.Dictionary")
For i = 4 To sh.Range("G" & Rows.Count).End(xlUp).Row
dic(sh.Range("G" & i).Value) = Empty
Next
ComboBox1.List = dic.keys
ListBox1.ColumnCount = 7
End Sub