I am trying to set up a dashboard that uses getpivotdata and places into a set table form (client's request). What I would like to be able to do is use VBA to change the date filter on 3 pivot tables that are located on a different sheet than the dashboard. I need the client to be able to enter a date in a cell on the dashboard sheet and then have the VBA change the date filters on 3 pivot tables located on a separate sheet. I have tried to do this based on code from DedicatedExcel.com by updating the fields within the code, but I am getting an error on Field.CurrentPage = NewDate. I also need to figure how to change not one but three pivot tables (all will have same date filter). Thank you in advance for any tips!
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
If Intersect(Target, Range("B1:B2")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewDate As String
'Here you amend to suit your data
Set pt = Worksheets("PivotTablesSheet").PivotTables("Ken_Offset")
Set Field = pt.PivotFields("Date")
NewCat = Worksheets("KenSummary").Range("B1").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewDate
pt.RefreshTable
End With
End Sub