Below VBA code does the process.
However, it does no show any data after completing the code process. Only way to see data in pivot rows is to manually drag date field in row and bringing it back up in filter field of pivot, after that it shows data - Anything missing in the below code ?
Testing result in Excel 2003 -
Does not display any data in pivot, even though the date field shows the range date selected. Only way it shows pivot data when you manually refresh or drag the date field in the row.
Testing result in Excel 2007 -
Does not show any data at the bottom plus on check pivot date field - the filter shows checkmark not only for date range entered but also for any month or year with days between 1 to 9.
1) Dates stored in pivot table as m/dd/yyyy
i.e. 6/02/2010, 6/01/2010, .... 5/15/2010...
(if date range entered is from 6/01/2010 to 6/30/2010. The above code will make selection in pivot from june 1st to june 30th 2010 and also for may 1st to may 9 2010, .....upto data that is available in pivot.)
2) Have tried changing system date for short date as m/dd/yyyy also tried format command for date in the code still the same - no effect in excel 2007 still shows date selected from 1 to 9 for any year.
However, it does no show any data after completing the code process. Only way to see data in pivot rows is to manually drag date field in row and bringing it back up in filter field of pivot, after that it shows data - Anything missing in the below code ?
Testing result in Excel 2003 -
Does not display any data in pivot, even though the date field shows the range date selected. Only way it shows pivot data when you manually refresh or drag the date field in the row.
Testing result in Excel 2007 -
Does not show any data at the bottom plus on check pivot date field - the filter shows checkmark not only for date range entered but also for any month or year with days between 1 to 9.
1) Dates stored in pivot table as m/dd/yyyy
i.e. 6/02/2010, 6/01/2010, .... 5/15/2010...
(if date range entered is from 6/01/2010 to 6/30/2010. The above code will make selection in pivot from june 1st to june 30th 2010 and also for may 1st to may 9 2010, .....upto data that is available in pivot.)
2) Have tried changing system date for short date as m/dd/yyyy also tried format command for date in the code still the same - no effect in excel 2007 still shows date selected from 1 to 9 for any year.
Code:
Sub Pivot_DateFilter()
Dim PivtTbl As PivotTable
Dim PivtFld As PivotField
Dim PivtItm As PivotItem
On Error Resume Next
Worksheets("Sheet1").Activate
Set PivtTbl = ActiveSheet.PivotTables("Table_Pivot1")
Set PivtFld = PivtTbl.PivotFields("Date")
PivtTbl.ManualUpdate = True
PivtFld.EnableMultiplePageItems = True
For Each PivotItem In ActiveSheet.PivotTables(PivtTbl). _
PivotField("Date"). _
PivotItems
If PivtItm.Value >= From_Date And _
PivtItm.Value <= To_Date Then
PivtItm.Visible = True
Else
PivtItm.Visible = False
End If
Next PivotItem
PivtFld.EnableMultiplePageItems = False
PivtItm.ManualUpdate = False
Set PivtFld = Nothing
Set PivtItm = Nothing
End Sub