I have a code to filter a pivot table to a range of dates no larger than 31 days. Since I know the length of the pivot table I have other data and information below the pivot table to work with. Problem is the data source has a much larger range of dates so when I use the .ClearAllFilters it wants to replace all of the data below before it filters to the correct range.
Here is my simple code:
Set pt = RepSheet.PivotTables("PivotTable1")
pt.PivotFields("Date").ClearAllFilters
pt.PivotFields("Date").PivotFilters.Add Type:=xlDateBetween, _
Value1:=SelectedDate1, Value2:=SelectedDate2
I have tried the code below to set the filters all to False instead of clearing the filters but I just get an error when trying to set the filters.
With pt.PivotFields("Date")
For i = 1 To .PivotItems.Count - 1
.PivotItems(.PivotItems(i).Name).Visible = False
Next i
End With
Any suggestions? I really don't want to put the data on top of the pivot table.
.PivotItems(SelectedDate1).Visible = Truein theWithstatement but still get same error, it is selected in the list but not appearing in the table, do I need to refresh? @GregViers - Senor Penguinif i = pivotitems.count and z = 0 then .visible = true. This ensure that at least 1 filter is applied to the data, even if the previous last filter was off. - Cyril