I'm new to VBA ... thanks for your patience and assistance.
I'm trying to create a report from multiple pivot tables on a single worksheet with each pivot table filter referencing a separate cell value in the worksheet.
I have VBA for each Worksheet_Change but I haven't been able to figure out how to merge them into a single Worksheet_Change as only one can exist within the worksheet.
Here are the three individual Worksheet_Change events (all work individually):
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("A1:A1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("NEW-District Report").PivotTables("PivotTable1")
Set xPFile = xPTable.PivotFields("District Name")
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("D1:D1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("NEW-District Report").PivotTables("PivotTable2")
Set xPFile = xPTable.PivotFields("District Name")
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("G1:G1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("NEW-District Report").PivotTables("PivotTable3")
Set xPFile = xPTable.PivotFields("District Name")
xStr = Target.Text
xPFile.ClearAllFilters
xPFile.CurrentPage = xStr
Application.ScreenUpdating = True
End Sub
I'm trying to create a report from multiple pivot tables on a single worksheet with each pivot table filter referencing a separate cell value in the worksheet.
I have VBA for each Worksheet_Change but I haven't been able to figure out how to merge them into a single Worksheet_Change as only one can exist within the worksheet.
Here are the three individual Worksheet_Change events (all work individually):
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("A1:A1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("NEW-District Report").PivotTables("PivotTable1")
Set xPFile = xPTable.PivotFields("District Name")
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("D1:D1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("NEW-District Report").PivotTables("PivotTable2")
Set xPFile = xPTable.PivotFields("District Name")
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("G1:G1")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("NEW-District Report").PivotTables("PivotTable3")
Set xPFile = xPTable.PivotFields("District Name")
xStr = Target.Text
xPFile.ClearAllFilters
xPFile.CurrentPage = xStr
Application.ScreenUpdating = True
End Sub