Hello All,
I am trying to filter a worksheeet based on the selections a user makes in a listbox; however, when the sheet filters, all of the data is blank. The listbox is populated dynamically with a set of timestamps from the column that will be filtered on based on selection. Looking for any help in why my code is not working.
Thanks in advance for any assistance with this!
I am trying to filter a worksheeet based on the selections a user makes in a listbox; however, when the sheet filters, all of the data is blank. The listbox is populated dynamically with a set of timestamps from the column that will be filtered on based on selection. Looking for any help in why my code is not working.
VBA Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
'Set workbook and worksheet variables
Dim WB As Workbook: Set WB = ActiveWorkbook
Dim shCompare As Worksheet
Set shCompare = WB.Worksheets("Fault Comparison")
'Filter MERS Report
Dim rngFound As Range
Dim Q As Long, n As Long
With Me.ListBox1
Dim arr() As Variant
Dim Q As Long, n As Long
For Q = 0 To .ListCount - 1
If .Selected(Q) Then
ReDim Preserve arr(0 To n)
arr(n) = .List(Q)
n = n + 1
End If
Next Q
End With
Set rngFound = WB.Sheets("Fault Comparison").Range("5:5").Find(What:="Test Timestamp", LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=True)
shCompare.Select
shCompare.Cells(5, rngFound.Column).Select
rngFound.AutoFilter Field:=rngFound.Column, Criteria1:=arr, Operator:=xlFilterValues
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub
Thanks in advance for any assistance with this!