Update row and colum filter of a pivot table with VBA

davsebsav

New Member
Joined
Apr 13, 2017
Messages
1
Hi there,

I have some difficulties updating the row and column filter of a Pivot table by using the value of two cells on a different spreadsheet. The main Report filter automatic update works fine but when I Change the Categories or Company the formula stop at this line:

pfcat.CurrentPage = categ

Does anyone have any idea about what could be the cause?

Thanks in advance for your help ;-)


Private Sub Worksheet_Change(ByVal Target As Range)
'The sub automatically update the PT filter according to the region in the Userform
Dim pvt As PivotTable
Dim pf As PivotField
Dim pfcat As PivotField
Dim pfcomp As PivotField
Dim region As String
Dim categ As String
Dim comp As String

Set pvt = Worksheets("Sheet2").PivotTables("PivotTable1")
Set pf = pvt.PivotFields("Geographies")
Set pfcat = pvt.PivotFields("Code Category")
Set pfcomp = pvt.PivotFields("Companies")
region = Worksheets("Userform").Range("D4").Value
categ = Worksheets("Userform").Range("F4").Value
comp = Worksheets("Userform").Range("B4").Value
With pvt
pf.ClearAllFilters
pf.CurrentPage = region
pfcat.ClearAllFilters
pfcat.CurrentPage = categ
pfcomp.ClearAllFilters
pfcomp.CurrentPage = comp
pvt.RefreshTable
End With
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,222,827
Messages
6,168,482
Members
452,192
Latest member
FengXue

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