Pessoal, podem me ajudar por favor?
Contextualizando, descobri um código que ao inserir um parâmetro em uma célula, ele ativa o filtro da tabela dinâmica em outra sheet. Por exemplo, na sheet "Dashbord", eu digito o ano 2018 na célula "E9", e automaticamente é ativado o filtro "Ano" na tabela dinâmica da sheet "Dinamicas". Este código é um "Worksheet_Change". O problema é que preciso filtrar mais de um parâmetro e em mais de uma tabela dinâmica. Por exemplo, preciso digitar os parâmetros "Ano" e "Unidade" na sheet "Dashboard" e ativar o filtro na "tabela1" e "tabela2 da sheet "Dinamicas".
Como eu poderia unificar estas quatro "Worksheet_Change"?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String
On Error Resume Next
If Intersect(Target, Range("E9")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("Dinamicas").PivotTables("Tabela1")
Set xPFile = xPTable.PivotFields("Ano")
xStr = Target.Text
xPFile.ClearAllFilters
xPFile.CurrentPage = xStr
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String
On Error Resume Next
If Intersect(Target, Range("E10")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("Dinamicas").PivotTables("Tabela1")
Set xPFile = xPTable.PivotFields("Unidade")
xStr = Target.Text
xPFile.ClearAllFilters
xPFile.CurrentPage = xStr
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String
On Error Resume Next
If Intersect(Target, Range("E9")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("Dinamicas").PivotTables("Tabela2")
Set xPFile = xPTable.PivotFields("Ano")
xStr = Target.Text
xPFile.ClearAllFilters
xPFile.CurrentPage = xStr
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String
On Error Resume Next
If Intersect(Target, Range("E10")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("Dinamicas").PivotTables("Tabela2")
Set xPFile = xPTable.PivotFields("Unidade")
xStr = Target.Text
xPFile.ClearAllFilters
xPFile.CurrentPage = xStr
Application.ScreenUpdating = True
End Sub
Obrigado
Felipe