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
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!
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
Thanks in advance for your time and help!