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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,845
Messages
6,127,259
Members
449,372
Latest member
charlottedv

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