Hi I'm trying to use VBA to filter pivot tables on a sheet by a date field from a data model, using a date range referenced in cells on the sheet,
The code here
... gives me a compile error at .ClearAllFilters. Is there something wrong with the way I'm referencing the CubeFields field?
(This is also posted on an old thread which started on another topic, here)
The code here
VBA Code:
VBA Code:
Sub Filter_PT_Date_Range()
Dim pt As PivotTable
For Each pt In Sheet2.PivotTables
With pt.CubeFields("[q Events].[Event Date]")
.ClearAllFilters
.PivotFilters.Add Type:=xlAfterOrEqualTo, Value1:=Format(Range("T3").Value, "dd mmm yyyy")
.PivotFilters.Add Type:=xlBeforeOrEqualTo, Value1:=Format(Range("T4").Value, "dd mmm yyyy")
End With
Next pt
End Sub
(This is also posted on an old thread which started on another topic, here)