PDA

View Full Version : VBA Pivot Table Update Run Time Error



DoodlesMama1
10-04-2013, 10:33 AM
Hello,
I am creating the report that is updated daily and need assistance with dates in Pivot Tables within the report.

I have one sheet within the report that is for service call aging and contains two pivot tables on it for one and seven days. Our reporting system runs one day behind, so the formula needs to actually be for 2 and 8 days.
One for any calls over 1 day. =Today()-2
One for any calls over 7 days. =Today()-8

Since these are within a Pivot Table, I have tried several variations to ensure the Pivot Table reflects all the data minus 1 day and 7 days, but keep getting an error. The error and VBA code are reflected below.



ERROR: Run-time error '1004: Unable to get the PivotItems property of the PivotField class.
VBA:


Sub Aging_Calls()

Dim OneDay As String
Dim SevenDay As String

OneDay = Format(Date - 2, "mm/dd/yyyy")
SevenDay = Format(Date - 8, "mm/dd/yyyy")

Sheets("Aging Calls").Select

'OLDER THAN ONE DAY
ActiveSheet.PivotTables("DBD4_Calls_Over_1Day").PivotFields("CONTACT DATE").CurrentPage = "(All)"
ActiveSheet.PivotTables("DBD4_Calls_Over_1Day").PivotFields("CONTACT DATE").PivotItems(OneDay).Visible = False

'OLDER THAN ONE WEEK
ActiveSheet.PivotTables("DBD4_Calls_Over_1Week").PivotFields("CONTACT DATE").CurrentPage = "(All)"
ActiveSheet.PivotTables("DBD4_Calls_Over_1Week").PivotFields("CONTACT DATE").PivotItems(SevenDay).Visible = False

End Sub

Can any of you please help me?