Guest User

Untitled

a guest
Jan 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  2. 'This line stops the worksheet updating on every change, it only updates when cell
  3. 'A1 to A9 is touched
  4. If Intersect(Target, Worksheets(1).Range("A1:A9")) Is Nothing Then Exit Sub
  5.  
  6. 'Set the Variables to be used
  7. Dim pt As PivotTable
  8. Dim Field As PivotField
  9. Dim NewCat As String
  10.  
  11. 'Here you amend to suit your data
  12. Set pt = Worksheets(1).PivotTables("PivotTable1")
  13. Set Field = pt.PivotFields("Sales Region")
  14. NewCat = Worksheets(1).Range("A1:A9").Value
  15.  
  16. 'This updates and refreshes the PIVOT table
  17. With pt
  18. Field.ClearAllFilters
  19. Field.CurrentPage = NewCat
  20. pt.RefreshTable
  21. End With
  22.  
  23.  
  24. End Sub
Add Comment
Please, Sign In to add comment