abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,494
- Office Version
- 2019
- 2010
- Platform
- Windows
Hi
codes will select the sheet name from combobox1 and populate based on sheet is selected from combobox1 and when write ID based on column D will search within sheet is selected from combobox1 . now I add combobox2 contains months (1,2.......)
what I want when select sheet from combobox 1 and select month(1) from combobox2 then should filter data in list box within selected sheet from combobox1 for just selected month(1) from combobox2 , also should deal with textbox1 when write ID . I mean if select sheet from combobox1 and month from combobox2 and write ID based on column D then should populate data in listbox within sheet & month based on the ID is written in textbox1 .
codes will select the sheet name from combobox1 and populate based on sheet is selected from combobox1 and when write ID based on column D will search within sheet is selected from combobox1 . now I add combobox2 contains months (1,2.......)
what I want when select sheet from combobox 1 and select month(1) from combobox2 then should filter data in list box within selected sheet from combobox1 for just selected month(1) from combobox2 , also should deal with textbox1 when write ID . I mean if select sheet from combobox1 and month from combobox2 and write ID based on column D then should populate data in listbox within sheet & month based on the ID is written in textbox1 .
VBA Code:
Option Explicit
Option Compare Text
Private Data, Temp, Crit As String, i As Long, ii As Long, x As Long
Dim WS As Worksheet
Private Sub ComboBox1_Change()
If ComboBox1.Value = "" Then Exit Sub
Set WS = Sheets(ComboBox1.Value)
Call LBoxPop
End Sub
Private Sub TextBox1_Change()
Crit = TextBox1
Call LBoxPop
End Sub
Private Sub UserForm_Initialize()
Crit = ""
Dim i As Long
For i = 5 To Sheets.Count
ComboBox1.AddItem Sheets(i).Name
Next
If ComboBox1.ListIndex > -1 Then
Set WS = Sheets(ComboBox1.Value)
Call LBoxPop
End If
End Sub
Private Sub LBoxPop()
Dim i&, ii&
Dim myFormat(1) As String
Data = WS.Cells(1).CurrentRegion.Value
x = 0
myFormat(0) = WS.Cells(2, 8).NumberFormatLocal
myFormat(1) = WS.Cells(2, 9).NumberFormatLocal
ReDim Temp(1 To UBound(Data, 1), 1 To 10)
For i = 1 To UBound(Data)
If Data(i, 4) Like Crit & "*" Or Data(i, 4) = "CODE" Then
x = x + 1
Temp(x, 2) = Format(Data(x, 2), "DD/MM/YYYY")
For ii = 1 To 10
Temp(x, ii) = Data(i, ii)
If ii >= 8 Then
Temp(x, ii) = Format$(Data(i, ii), myFormat(1))
End If
Next ii
End If
Next i
With UserForm1.ListBox1
.ColumnCount = 10
.ColumnWidths = "80;80;120;80;60;60;60;60;60;60"
.List = Temp
End With
End Sub