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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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.
 
Upvote 0
For the early crowd. Might disable this for now until I can work out a solution. Will post back with an update.
 
Upvote 0
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 :)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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
Back
Top