Hello. New member. I had a situation with a dashboard (Excel 2013) that consists of various tables, charts, and text. We been asked to expand the backend data and allow a user to choose their own dates. At first I thought this would be easy by way of Slicers and the Timeline function. However, I've since discovered that will only affect multiple PivotTables if they are derived from the same source.
To setup my own solution I pulled together some VBA to adjust date ranges in the source tables. That worked, but I soon realize that won't adjust the associated Pivot tables.
Now I'm trying to get VBA to instead adjust the pivot table date ranges in the FILTER area. I created a sample workbook with the following code that worked:
I've tried to apply this to a copy of the source workbook without success. I've even tried pulling source workbook data to a new workbook with no success.
When I apply the my workbook, I receive the following with the rror on the last row.
I thought it might be a date formatting issue, and adjusted accordingly, but to no avail.
I conducted some more research this morning and found some useful posts by Jerry Sullivan, but couldn't get any of those to work either.
Pivot table with data validation
Update Pivot Table using Date Ranges outside the Pivot Table
VBA help to update pivottable date filter with a single cell value date
To setup my own solution I pulled together some VBA to adjust date ranges in the source tables. That worked, but I soon realize that won't adjust the associated Pivot tables.
Now I'm trying to get VBA to instead adjust the pivot table date ranges in the FILTER area. I created a sample workbook with the following code that worked:
Code:
Sub Button1_Click()
Dim pt As PivotTable
Set pt = Sheets("Sheet1").PivotTables("PivotTable1")
pt.PivotFields("Date").ClearAllFilters
pt.PivotFields("Date").CurrentPage = Range("B2").Value
End Sub
I've tried to apply this to a copy of the source workbook without success. I've even tried pulling source workbook data to a new workbook with no success.
When I apply the my workbook, I receive the following with the rror on the last row.
Run-time error '1004': Application-defined or object-defined error
I thought it might be a date formatting issue, and adjusted accordingly, but to no avail.
I conducted some more research this morning and found some useful posts by Jerry Sullivan, but couldn't get any of those to work either.
Pivot table with data validation
Update Pivot Table using Date Ranges outside the Pivot Table
VBA help to update pivottable date filter with a single cell value date