VBA Code - Selecting pivot table filter based on cell on another worksheet

Yong0195

New Member
Joined
Oct 23, 2018
Messages
1
Hello, I can't seem to crack this problem. I wish to select the filter on my pivot table based on another cell in another worksheet. Can anyone point me in the right direction?

The worksheet my pivot table is on is named "Undesirable Submission" and the name of the pivot table is PivotTable2.
The filter name is "Month".

The worksheet I will retrieve the filter information is named "Introduction". And the relevant cell is F3.

==
The code I have is this:

'This line stops the worksheet updating on every change
If Intersect(Target, Introduction.Range("F3")) Is Nothing Then Exit Sub


'Set the Variables to be used
Dim PTable2 as PivotTable
Dim Field As PivotField
Dim NewCat As String


'Here you amend to suit your data
Set Field = PTable2.PivotFields("Month")
NewCat = Introduction.Range("F3").Value


'This updates and refreshes the PIVOT table
With PTable2
Field.ClearAllFilters
Field.CurrentPage = NewCat
PTable2.RefreshTable
End With


End Sub

==

Thanks in advance for the help!!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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