Hi all,
Is there a way for me to use the same code for multiple pivot tables (not all), these pivots are on the same sheet?
Thank you.
Regards,
Tejal Sorathia
Is there a way for me to use the same code for multiple pivot tables (not all), these pivots are on the same sheet?
Code:
Sub PivotTableFieldValues1()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheet5.Pivottables("PivotTable1").PivotCache.Refresh
Dim Pt As PivotTable
Dim Pi As PivotItem
Sheet5.Pivottables("PivotTable1").PivotFields("Date Range"). _
ClearAllFilters
Set Pt = Sheet5.Pivottables("PivotTable1")
For Each Pi In Pt.PivotFields("Date Range").PivotItems
On Error Resume Next
If Pi.Name = Range("startdaycomp") Or Pi.Name = Range("finishdaycomp") Then
Pi.Visible = True
Else: Pi.Visible = False
End If
Next Pi
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Thank you.
Regards,
Tejal Sorathia