Excel VBA - Pivotfield filter doesn't update pivot table

thiagofb

New Member
Joined
Jan 31, 2019
Messages
1
Hello everyone,
This is my first topic :)
I will explain in details :
I have 4 pivot tables from different sources.
I have another table with a list that I need to filter at the pivot table.
In the end I expect to create a macro that reads this list, apply the filter and print the result for each filter.

My problem : I am stuck to update the pivot table, I can change automatically all the filters but sometimes it does not update the results at table, sometimes it only changes the filter title.

Do you know what it could be? Below you'll see the VBA.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Intersect(Target, Range("L55:L56")) Is Nothing Then Exit Sub

'Set the Variables to be used
Dim PT1 As PivotTable, PT2 As PivotTable, PT3 As PivotTable, PT4 As PivotTable
Dim Field As PivotField
Dim NewCat As String

'Here you amend to suit your data


Set PT1 = Worksheets("mise en compensation FR").PivotTables("Tableau croisé dynamique1")
Set PT2 = Worksheets("mise en compensation FR").PivotTables("Tableau croisé dynamique2")
Set PT3 = Worksheets("mise en compensation FR").PivotTables("Tableau croisé dynamique3")
Set PT4 = Worksheets("mise en compensation FR").PivotTables("Tableau croisé dynamique4")


NewCat = Worksheets("mise en compensation FR").Range("L55").Value


'This updates and refreshes the PIVOT table


Set Field = PT1.PivotFields("NOM Transporteur")


With PT1
Field.CurrentPage = NewCat
PT1.RefreshTable
End With




Set Field = PT2.PivotFields("NOM Transporteur")


With PT2
Field.CurrentPage = NewCat
PT2.RefreshTable
End With




Set Field = PT3.PivotFields("NOM FOURNISSEUR")


With PT3
Field.CurrentPage = NewCat
PT3.RefreshTable
End With




Set Field = PT4.PivotFields("NOM FOURNISSEUR")


With PT4
Field.CurrentPage = NewCat
PT4.RefreshTable
End With


End Sub


Thank you all and I'm sorry for my english mistakes :)
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,584
Messages
6,125,666
Members
449,248
Latest member
wayneho98

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