Displaying Pivot Table items with a loopy loop
So I have a pivot table with a date filter. I want to only display the dates that are within the last 63 days. Sinch! Just a freakin loop adding negatives.
However, some of these dates have a time after them.
So what I need to figure out, is can I have some sort of wild card or Left() integrated into the loop.
Here is what I have, and would work if my data souurce didn't suck.
Code:
For i = -1 To -63 Step -1
ActiveSheet.PivotTables("PivotTable3").PivotFields("LST_XP_DAT").PivotItems(CStr(DateAdd("d", i, Date))).Visible = True
DoEvents
Next
Re: Displaying Pivot Table items with a loopy loop
Woohoo, got it. This does exactly what I need so I will post it as an FYI.
Code:
Dim PName$()
For i = 1 To 10000
PName = Split(ActiveSheet.PivotTables("PivotTable3").PivotFields("LST_XP_DAT").PivotItems(i).Name, " ")
If DateDiff("d", PName(0), Date) <= 0 Then Exit For
If DateDiff("d", PName(0), Date) < 63 Then ActiveSheet.PivotTables("PivotTable3").PivotFields("LST_XP_DAT").PivotItems(i).Visible = True
DoEvents
Next