hello all,
i have set up a macro to validate which pivot chart fields are selected and edit text in the chart title based on that. so the idea is the user can set the filters within the chart and see which regions are selected in the title.
this code will step through ok but if run on its own excel will crash.
the pivot table event runs from the pivot chart which is on a different sheet to the pivot table. any suggestions for what might be the problem? thanks,
i have set up a macro to validate which pivot chart fields are selected and edit text in the chart title based on that. so the idea is the user can set the filters within the chart and see which regions are selected in the title.
this code will step through ok but if run on its own excel will crash.
the pivot table event runs from the pivot chart which is on a different sheet to the pivot table. any suggestions for what might be the problem? thanks,
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim wsSewer, wsCharts As Worksheet
Dim chtTitle As String
Dim north, northwest, south As Boolean
Set wsSewer = ActiveWorkbook.Worksheets("sewer block choke pt")
Set wsCharts = ActiveWorkbook.Worksheets("Charts")
north = wsSewer.PivotTables("sewerPT").PivotFields("Region Name").PivotItems("North").Visible
northwest = wsSewer.PivotTables("sewerPT").PivotFields("Region Name").PivotItems("NorthWest").Visible
south = wsSewer.PivotTables("sewerPT").PivotFields("Region Name").PivotItems("South").Visible
wsCharts.ChartObjects("sewer pc").Activate
If north Then
If northwest Then
If south Then
chtTitle = "All"
Else
chtTitle = "North & North West"
End If
Else
If south Then
chtTitle = "North & South"
Else
chtTitle = "North"
End If
End If
Else
If northwest Then
If south Then
chtTitle = "North West & South"
Else
chtTitle = "North West"
End If
Else
If south Then chtTitle = "South"
'End If
End If
End If
With wsCharts.ChartObjects("sewer pc")
.Chart.HasTitle = True
.Chart.ChartTitle.Text = chtTitle
End With
End Sub