Hello,
I'm trying to change the filter of my pivot tables with a value in a cell.
This is working, but I think it is a bit slow.
And with this solution I can not put the pivot tables above each other. And that is what i want.
Code
Sub Macro3()
Dim jaar, maand As String
With ThisWorkbook.Worksheets("Dashboard")
jaar = .Range("C2").Value
maand = .Range("C3").Value
End With
On Error GoTo Errorhandler1
ActiveSheet.PivotTables("Lijn1").PivotFields("Jaar").ClearAllFilters
ActiveSheet.PivotTables("Lijn1").PivotFields("Jaar").CurrentPage = jaar
On Error GoTo Errorhandler2
ActiveSheet.PivotTables("Lijn1").PivotFields("Maand").ClearAllFilters
ActiveSheet.PivotTables("Lijn1").PivotFields("Maand").PivotFilters.Add Type:= _
xlCaptionEquals, Value1:=maand
ActiveSheet.PivotTables("Lijn2").PivotFields("Jaar").ClearAllFilters
ActiveSheet.PivotTables("Lijn2").PivotFields("Jaar").CurrentPage = jaar
ActiveSheet.PivotTables("Lijn2").PivotFields("Maand").ClearAllFilters
ActiveSheet.PivotTables("Lijn2").PivotFields("Maand").PivotFilters.Add Type:= _
xlCaptionEquals, Value1:=maand
ActiveSheet.PivotTables("Test").PivotFields("Jaar").ClearAllFilters
ActiveSheet.PivotTables("Test").PivotFields("Jaar").CurrentPage = jaar
ActiveSheet.PivotTables("Test").PivotFields("Maand").ClearAllFilters
ActiveSheet.PivotTables("Test").PivotFields("Maand").PivotFilters.Add Type:= _
xlCaptionEquals, Value1:=maand
Exit Sub
Errorhandler1:
MsgBox ("Het jaartal is niet bekend.")
Exit Sub
Errorhandler2:
MsgBox ("De maand is niet bekend.")
End Sub
Display More
Does anyone had a solution to have the code in such a way that I can put my pivot tables above each other?
And does anyone know how I can make the code faster?
Thanks in advance!