VBA for Updating Pivot Table Filters

jerry0921

New Member
Joined
Mar 2, 2018
Messages
1
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.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top