Pivot Chart Confusing Primary and Secondary Axes - VBA

ollyboly

New Member
Joined
Feb 11, 2014
Messages
1
I'm having a bit of difficulty getting Excel to play nice.
Simply put, i've got a Pivot Chart that doesn't know which its xlValue axes are.

I have a piece of VBA to format the chart that sporadically works and then gets confused again.

I've tried everything I can think of to get this working but nothing is consistent.
Below is the formatting code. Its the bottom section that is playing up.

See the comments at the bottom section of the code

Code:
Sub formatChartRGB()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


    Sheets("Graph").Select
    'ActiveSheet.ChartObjects("chart").Select
    Dim co As ChartObject
    Dim c As Chart
    Dim s As Series
    Dim l As LegendEntry
    
    Dim cnt As Long
    
    Set co = ActiveSheet.ChartObjects("chart")
    Set c = ActiveSheet.ChartObjects("chart").Chart
    
    With co
        .Width = 900
        .Height = 300
        .Left = 10
        .Top = 85
    End With
    c.PlotArea.Height = 260
    
    With c
        For cnt = .SeriesCollection.Count To 1 Step -1 'cnt = number of series entry working on
            With .SeriesCollection(cnt)
                        'cnt = cnt + 1
                        If .name Like "*Outage" Then
                            'Debug.Print .name & " - Outage"
                                .AxisGroup = xlSecondary
                                .ChartType = xlColumnClustered
                                With .Format.Line
                                    .Visible = msoTrue
                                    '.DashStyle = msoLineLongDash
                                    .DashStyle = msoLineSolid
                                    .ForeColor.rgb = rgb(0, 0, 255)
                                End With
                                .Format.Fill.ForeColor.rgb = rgb(0, 0, 255)
                                .Format.Fill.Solid
                        End If
                        If .name Like "*Case" Then
                            'Debug.Print .name & " - Case"
                                .AxisGroup = xlSecondary
                                .ChartType = xlColumnClustered
                                With .Format.Line
                                    .Visible = msoTrue
                                    .DashStyle = msoLineSolid
                                    .ForeColor.rgb = rgb(255, 0, 0)
                                End With
                                With .Format.Fill
                                .ForeColor.rgb = rgb(255, 0, 0)
                                .Patterned msoPatternDarkHorizontal
                                .BackColor.rgb = rgb(255, 255, 255)
                            End With
                        End If
                        If .name Like "*Check" Then
                            'Debug.Print .name & " - Check"
                                .AxisGroup = xlPrimary
                                .ChartType = xlLine
                                With .Format.Line
                                    .Visible = msoTrue
                                    .DashStyle = msoLineSolid
                                    .ForeColor.rgb = rgb(0, 255, 0)
                                    .Transparency = 0.5
                                    .Weight = 1
                                End With
                                .Format.Fill.ForeColor.rgb = rgb(0, 255, 0)
                        End If
            End With
        Next cnt


        'General Chart Formatting - NOT WORKING
        'On Error Resume Next ' Below 5 lines - tried removing chart elements and adding again
            .HasAxis(xlValue, xlSecondary) = False
            .HasAxis(xlValue, xlPrimary) = False
            .HasAxis(xlCategory) = False
            .Axes(xlValue, xlPrimary).HasTitle = False
            .Axes(xlValue, xlSecondary).HasTitle = False
        
            .HasAxis(xlValue, xlPrimary) = True
            .HasAxis(xlValue, xlSecondary) = True
            .SetElement (msoElementPrimaryCategoryAxisShow) 'Show date axes
            '.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis) 'Show Check title
            .Axes(xlValue, xlPrimary).HasTitle = True
            .Axes(xlValue, xlPrimary).AxisTitle.text = "Check Count"
            .Axes(xlValue, xlPrimary).Format.Line.ForeColor.rgb = rgb(0, 255, 0)
            .Axes(xlValue, xlPrimary).Format.Line.BackColor.rgb = rgb(0, 255, 0)
            .Axes(xlValue, xlPrimary).Format.Line.Weight = 1
            If (.HasAxis(xlValue, xlSecondary)) Then
                .SetElement (msoElementSecondaryValueAxisTitleAdjacentToAxis)
                .Axes(xlValue, xlSecondary).HasTitle = True
                .Axes(xlValue, xlSecondary).AxisTitle.text = "Outage / Case count"
                .Axes(xlValue, xlSecondary).Format.Line.ForeColor.rgb = rgb(0, 0, 255)
                .Axes(xlValue, xlSecondary).Format.Line.BackColor.rgb = rgb(255, 0, 0)
            End If
        'On Error GoTo 0
    End With
End Sub
I have an image that displays a series formatted as plotted to the Primary Axes and in fact is line sup to the Secondary axes - but i don't know how to post images?

Thanks in advance for your time and help!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,216,762
Messages
6,132,576
Members
449,737
Latest member
naes

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