0

I'm attempting to write a VBA code to filter my pivot table based on the Start and End Time a user enters into a cell.

My goal is for users to enter Start Time in "T6" and End Time in "U6" - When they click submit, then it would filter the table below to those times and maintain all of the other filters and formats.

Here's a SS of the pivot table.

enter image description here

I tried this code & it doesn't present any errors, but it also doesn't do anything.

The only value calculated in the pivot table is the "Departed Cube" column. Target Cube, Utilization Flag and Mileage Band are a table.

Sub VRID_DD_SDTFilter()
    
    Dim wsPivot As Worksheet
    
    Set wsPivot = ThisWorkbook.Sheets("Mid-Shift Tracker")
    
    If wsPivot.Range("T6").Value = "" Then
        MsgBox ("Please enter a start time.")
        Exit Sub
    End If
    
     If wsPivot.Range("U6").Value = "" Then
        MsgBox ("Please enter an end time.")
        Exit Sub
    End If
        
    With wsPivot.PivotTables("VRID DD").PivotFields("SDT_Time")
        .ClearAllFilters
        .PivotFilters.Add _
            Type:=xlValueIsBetween, DataField:=wsPivot.PivotTables("VRID DD"). _
            PivotFields("Departed Cube"), Value1:=wsPivot.Range("T6").Value, Value2:=wsPivot.Range("U6").Value
    End With
        
End Sub
QRLess
  • 23
  • 5

0 Answers0