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
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