Hello all!
I am new to VBA I am trying to update multiple pivot tables on sheet "data", based on drop down list on sheet "Flash" to update graphs on sheet "Flash" as well.
I found the code to update a single pivot table but editing it to do several gives me an error at [FONT="]pt.RefreshTable.
[/FONT]
Thanks!
I am new to VBA I am trying to update multiple pivot tables on sheet "data", based on drop down list on sheet "Flash" to update graphs on sheet "Flash" as well.
I found the code to update a single pivot table but editing it to do several gives me an error at [FONT="]pt.RefreshTable.
[/FONT]
Thanks!
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'B4 is touched
If Intersect(Target, Range("B4")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim ws As Worksheet
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set ws = Worksheets("data")
For Each pt In ws.PivotTables
Set Field = pt.PivotFields("Owner")
Next pt
NewCat = Worksheets("Flash").Range("B4").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
:warning:[FONT=arial black]pt.RefreshTable[/FONT]:warning:
End With
End Sub