RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
I have a table that has 7 columns and 122 rows.
Columns: Date, Time, East/West, Status, Activity, Comments, Date+Time
The Date and Time are separated and I use that last column for time filtering. It's that third column that's giving me all the trouble - East/West. When I filter for either "East" or "West" the table shows all the relevant entries so no problem there. But when I try to convert it to a listbox via the code below, hidden rows are getting in the way of transferring the table result to the listbox.
For example, if I filter for 'east' and rows 2, 3, 4, 5 are east, east, east, west (i.e. row 5 is hidden) - then I'll get rows 2, 3, 4 transferred to the listbox - no problem
, if I filter for 'east' and rows 2, 3, 4, 5 are east, west, east, west (i.e. rows 3, 5 are hidden) - then I'll only get row 2 transferred to the listbox even those the table shows all east entries
Just FYI - I have three optionbuttons choosing East/West/or Both
Columns: Date, Time, East/West, Status, Activity, Comments, Date+Time
The Date and Time are separated and I use that last column for time filtering. It's that third column that's giving me all the trouble - East/West. When I filter for either "East" or "West" the table shows all the relevant entries so no problem there. But when I try to convert it to a listbox via the code below, hidden rows are getting in the way of transferring the table result to the listbox.
For example, if I filter for 'east' and rows 2, 3, 4, 5 are east, east, east, west (i.e. row 5 is hidden) - then I'll get rows 2, 3, 4 transferred to the listbox - no problem
, if I filter for 'east' and rows 2, 3, 4, 5 are east, west, east, west (i.e. rows 3, 5 are hidden) - then I'll only get row 2 transferred to the listbox even those the table shows all east entries
Just FYI - I have three optionbuttons choosing East/West/or Both
VBA Code:
Private Sub SummarizeData()
Dim wSht As Worksheet
Dim rRange As Range
Dim tempArray() As Variant
Dim i As Long
Set wSht = ThisWorkbook.Worksheets("RawData")
Set rRange = wSht.Range("rngData")
If wSht.AutoFilterMode Then wSht.AutoFilter.ShowAllData
'Filter the table for time (dStartDate_PVar and dEndDate_PVar are public variables set by two DTPickers on another userform)
'dStartTime_PVar and dEndTime_PVar are public variables for time
wSht.ListObjects("Table1").Range.AutoFilter Field:=7, Criteria1:=">=" & CDbl(dStartDate_PVar + dStartTime_PVar), Operator:=xlAnd, Criteria2:="<=" & CDbl(dEndDate_PVar + dEndTime_PVar)
'For East West do another filter
'Each of these work - when I go to the worksheet it's all been filtered correctly
If Me.obShowEast.Value = True Then
wSht.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:="=East"
ElseIf Me.obShowWest.Value = True Then
wSht.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:="=West"
ElseIf Me.obShowBoth.Value = True Then
wSht.ListObjects("Table1").Range.AutoFilter Field:=3, Criteria1:="=East", Operator:=xlOr, Criteria2:="=West"
End If
'This is where it goes wonky. If I have an east, east, east, west it'll show 3 easts
'If I have a east, east, west it'll show 2 easts
'If I have a east, west, east it'll show only the first east
Set rRange = rRange.Rows.SpecialCells(xlCellTypeVisible)
tempArray = rRange.Value
'Second column is time which has to be formated
For i = 1 To UBound(tempArray)
tempArray(i, 2) = Format(tempArray(i, 2), "h:mm AM/PM")
Next i
'Populate the ListBox
Me.lbHistory.List = tempArray
Me.lbHistory.Selected(0) = True
Me.lblCount.Caption = Me.lbHistory.ListCount
End Sub