VBA, opdatere pagefield i to pivotballer fra dropdown liste
HejJeg kan ikke få denne kode til at opdatere begge pivot tabeller. Kun den ene "Pivot1".
Er der nogen der kan se hvad fejlen er ?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pt = Worksheets("Pivot1").PivotTables("tabel1")
Set pf = pt.PageFields("Name")
Dim tjek As String
Dim pt2 As PivotTable
Dim pf2 As PivotField
Dim pi2 As PivotItem
Set pt2 = Worksheets("Pivot2").PivotTables("tabel2")
Set pf2 = pt2.PageFields("Name")
If Target.Address = "$C$2" Then
Application.EnableEvents = False
For Each pi In pf.PivotItems
If LCase(Target.Value) = "alle" Then
tjek = "(All)"
ElseIf LCase(pi.Value) = LCase(Target.Value) Then
tjek = pi.Value
Exit For
End If
Next pi
pf.CurrentPage = tjek
pf2.CurrentPage = tjek
Application.EnableEvents = True
End If
End Sub