I am working on filtering a listbox based on the combobox selection.
Currently my codes look something like this.
Private Sub OEMNumberComboBox_Change()
Dim database(1 To 100, 1 To 7)
Dim i As Integer
Dim My_range As Integer
Dim colum As Byte
On Error Resume Next
Sheet7.Range("A1").AutoFilter field:=3, Criteria1:=Me.OEMNumberComboBox.Value
For i = 2 To Sheet7.Range("A100000").End(xlUp).Row
If Sheet7.Cells(i, 3) = Me.OEMNumberComboBox Then
My_range = My_range + 1
For colum = 1 To 7
database(My_range, colum) = Sheet7.Cells(i, colum)
Next colum
End If
Next i
ListBox1.List = database
End Sub
and the below during the intialisation
Sub Available_Stocks()
Application.ScreenUpdating = False
Dim invd_sh As Worksheet
Set invd_sh = ThisWorkbook.Sheets("Inventory")
Dim lr As Integer
lr = Application.WorksheetFunction.CountA(invd_sh.Range("A:A"))
If lr = 1 Then lr = 2
With Me.ListBox1
.ColumnCount = 9
.ColumnHeads = True
.ColumnWidths = "50,60,60,350,50,0,0,50,50"
.RowSource = "Inventory!A2:I" & lr
End With
End Sub
with the above codes it does filter the range but it is not reflected on the listbox and I am not sure what is wrong with the code.
It is exact copy of the online codes but i have made a slight modification (so that it is filtering column C).
user interface/objects
Update
Private Sub UserForm_Initialize()
'add column of data from spreadsheet to your userform ComboBox
OEMNumberComboBox.List = Sheets("Sheet1").Range("C1:C50").Value
End Sub
I have added the above code to populate the combobox but it sill shows one cell inside the listbox
question from:
https://stackoverflow.com/questions/65878743/filter-a-listbox-based-on-combobox 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…