NormChart55
New Member
- Joined
- Feb 22, 2022
- Messages
- 44
- Office Version
- 2016
- Platform
- Windows
Hello All,
I am trying to have a pivot table filter change to be what is in another cell. We use a template that has a SKU list and the user can use a select macro to copy the SKU into another more in depth analysis page which pulls a bunch of other data. But we have to then manually change the pivot table filter. I am wanting the filter to update to what is in the other cell. I found a simple one online, but seems to not actually do anything despite to me what looks to be correct references. After the users select the SKU, it copies that into the other sheet cell D668 and that is the one I want the filter to also adjust to. I am not sure why this does not seem to do anything. any thoughts?
PivotTable6 is the pivot
Product SKU is the field
D668 is the cell that is changing.
I am trying to have a pivot table filter change to be what is in another cell. We use a template that has a SKU list and the user can use a select macro to copy the SKU into another more in depth analysis page which pulls a bunch of other data. But we have to then manually change the pivot table filter. I am wanting the filter to update to what is in the other cell. I found a simple one online, but seems to not actually do anything despite to me what looks to be correct references. After the users select the SKU, it copies that into the other sheet cell D668 and that is the one I want the filter to also adjust to. I am not sure why this does not seem to do anything. any thoughts?
PivotTable6 is the pivot
Product SKU is the field
D668 is the cell that is changing.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'D668 is touched
If Intersect(Target, Range("D668:D669")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("JDE Template").PivotTables("PivotTable6")
Set Field = pt.PivotFields("Product SKU")
NewCat = Worksheets("JDE Template").Range("D668").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub