I have 3 separate PT on a worksheet. Each PT's datasource is linked to a separate tab. I would like to control the filter "employee filter" by typing/selecting the employee's name on cell A3 (whicheve cell).
I've looked around in the forums and found a few threads with almost the same request, but none that seem to work. Taking bits and pieves from each thread I was able to write the following:
This is what I have so far and it "kind of works" (i'm new at VBA):
Sub filter_all_tables()
'
' filter_all_tables Macro
'
'
Range("C3").Select
Selection.Copy
ActiveSheet.PivotTables("PivotTable3").PivotFields("Collector filter"). _
CurrentPage = "(All)"
On Error Resume Next
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Collector filter"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Collector filter"). _
CurrentPage = "c3"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Collector filter"). _
CurrentPage = Range("c3").Value
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Collector filter"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Collector filter"). _
CurrentPage = Range("c3").Value
End With
ActiveSheet.PivotTables("PivotTable3").PivotFields("Collector filter"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable3").PivotFields("Collector filter"). _
CurrentPage = Range("c3").Value
Range("A5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Range("C3").Select
End Sub
The problem that i am having is, whever i select an employee name that is not lited on any of the tables, the tables then lists everyone. I would like the table to be blank/display nothing if the employee is not found.
I hope i'm explaining this correctly. Thanks for your time!
I've looked around in the forums and found a few threads with almost the same request, but none that seem to work. Taking bits and pieves from each thread I was able to write the following:
This is what I have so far and it "kind of works" (i'm new at VBA):
Sub filter_all_tables()
'
' filter_all_tables Macro
'
'
Range("C3").Select
Selection.Copy
ActiveSheet.PivotTables("PivotTable3").PivotFields("Collector filter"). _
CurrentPage = "(All)"
On Error Resume Next
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Collector filter"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Collector filter"). _
CurrentPage = "c3"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Collector filter"). _
CurrentPage = Range("c3").Value
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Collector filter"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable2").PivotFields("Collector filter"). _
CurrentPage = Range("c3").Value
End With
ActiveSheet.PivotTables("PivotTable3").PivotFields("Collector filter"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable3").PivotFields("Collector filter"). _
CurrentPage = Range("c3").Value
Range("A5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = ""
Range("C3").Select
End Sub
The problem that i am having is, whever i select an employee name that is not lited on any of the tables, the tables then lists everyone. I would like the table to be blank/display nothing if the employee is not found.
I hope i'm explaining this correctly. Thanks for your time!