I have already referred to a few other threads relating to this issue, but none of the answers have resolved my problem. I'm trying to select Pivot Items in a Pivot Field whose dates are equal to yesterday, the day before yesterday, and two days before yesterday.
I have tried changing my code so that I only ever write that xxx.Visible = False (as opposed to true), refreshing the table, and changing the "Number of items to retain per field" pivot table option to "None."
Here is my current code - any suggestions would be greatly appreciated!
ActiveSheet.PivotTables("PivotTable1").RefreshTable
ActiveSheet.PivotTables("PivotTable1").PivotFields("Complete Date"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Complete Date")
.ClearAllFilters
For Each ptItem In .PivotItems
If "2/3/15" = ptItem Then 'I still have the problem when I enter an actual date as opposed to the Now function
ptItem.Visible = True
ElseIf (Now - 2) = ptItem Then
ptItem.Visible = True
ElseIf (Now - 3) = ptItem Then
ptItem.Visible = True
Else
ptItem.Visible = False
End If
Next
End With
End Sub