Private Sub Worksheet_Change(ByVal Target As Range)
'Cette macro permet de changer tous les Champs de page "DateRéférence" des TCD du fichier
'en fonction de la valeur de la cellule D2
Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String
strField = "DateRéférence"
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Address = Range("D2").Address Then 'adresse de la cellule où l'on choisit la date à filtrer
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
With pt.PageFields(strField)
For Each pi In .PivotItems
If pi.Value = Target.Value Then
.CurrentPage = Target.Value
Exit For
Else 'sinon, afficher tous les enregistrements
.CurrentPage = "(Tous)"
End If
Next pi
End With
Next pt
Next ws
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub