dynamic update pivot chart title

joecast

Board Regular
Joined
Mar 4, 2010
Messages
52
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,


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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

joecast

Board Regular
Joined
Mar 4, 2010
Messages
52
hmmm. still causing a problem. now crashes when stepping through too. seems to get to the end of the code so will update the chart title but will crash after end sub call.
 

joecast

Board Regular
Joined
Mar 4, 2010
Messages
52
For the early crowd. Might disable this for now until I can work out a solution. Will post back with an update.
 

joecast

Board Regular
Joined
Mar 4, 2010
Messages
52
Seems Ive solved the problem. Had to do with which sheet was active when the chart title edit was happening. Added a line for sheet select and now works fine :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,629
Messages
5,838,454
Members
430,549
Latest member
jayjay2022

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top