Hello,
I am creating a report with 4 criteria that the end user will be able to update via a data validation list on the primary tab. So far, I am only able to update the "VP" filter from the pivot table, but I'm trying to figure out how the other 3 cells can be used to update the other filters on the pivot table. As a reference, the other 3 filters are: "Org Function," "Cost Center" and "Cost Center Owner"
I have the below code so far:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FTW As String
If Not Intersect(Target, Range("D3")) Is Nothing Then
FTW = Worksheets("Trended P&L").Range("D3").Value
Worksheets("Travel").Range("B2").Value = FTW
End If
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("Travel").PivotTables("PivotTable1")
Set Field = pt.PivotFields("VP")
NewCat = Worksheets("Travel").Range("B2").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub
I don't know VBA very well and I have a feeling that the code needs to be redone in order for it to work with the other filters.
I am creating a report with 4 criteria that the end user will be able to update via a data validation list on the primary tab. So far, I am only able to update the "VP" filter from the pivot table, but I'm trying to figure out how the other 3 cells can be used to update the other filters on the pivot table. As a reference, the other 3 filters are: "Org Function," "Cost Center" and "Cost Center Owner"
I have the below code so far:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim FTW As String
If Not Intersect(Target, Range("D3")) Is Nothing Then
FTW = Worksheets("Trended P&L").Range("D3").Value
Worksheets("Travel").Range("B2").Value = FTW
End If
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("Travel").PivotTables("PivotTable1")
Set Field = pt.PivotFields("VP")
NewCat = Worksheets("Travel").Range("B2").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.CurrentPage = NewCat
pt.RefreshTable
End With
End Sub
I don't know VBA very well and I have a feeling that the code needs to be redone in order for it to work with the other filters.