I'm looking for someone to help me with the below VBA. With one Pivot table on the code the macro runs perfect, but when I add a second table to the code I get a "Expected End With" error:
Sub TestPivot2()
'TestPivot Macro
Dim dt As String
dt = Sheets("Calendar View").Range("valSelEmployee").Value
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Employee Name")
With ActiveSheet.PivotTables("PivotTable2").PivotFields("List of Employees")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=dt
End With
End Sub
Sub TestPivot2()
'TestPivot Macro
Dim dt As String
dt = Sheets("Calendar View").Range("valSelEmployee").Value
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Employee Name")
With ActiveSheet.PivotTables("PivotTable2").PivotFields("List of Employees")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=dt
End With
End Sub