Hi,
I'd like to select the start date & end date for multiple Pivots (on one sheet).
Expl. if I put in a date in the "Start Date" cell : 01/01/2010 and another date in the "End Date" cell : 15/01/2010. Then all the pivots on the sheet should only show the date between 01/01 and 15/01/2010.
The dates in the pivots are under column "Date".
I have a code but it only selects 1 pivot and it doesn't refresh the pivots when you change the dates selection...
Could you help me ?
Sub FilterPivotDates()
'
Dim dStart As Date
Dim dEnd As Date
Dim pt As pivotTable
Dim pf As PivotField
Dim pi As PivotItem
Application.ScreenUpdating = False
On Error Resume Next
dStart = Sheets("Data").Range("StartDate").Value
dEnd = Sheets("Data").Range("EndDate").Value
Set pt = ActiveSheet.PivotTables(2)
Set pf = pt.PivotFields("Date")
pt.ManualUpdate = True
pf.EnableMultiplePageItems = True
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
For Each pi In pf.PivotItems
If pi.Value < dStart Or pi.Value > dEnd Then
pi.Visible = False
End If
Next pi
Application.ScreenUpdating = False
pt.ManualUpdate = False
Set pf = Nothing
Set pt = Nothing
End Sub
Bookmarks