Hello -
I am attempting to add a series on the xlSecondary axis of a PivotChart of BarStacked type. Please note that the data for the other series is not contained within the underlying PivotTable/ PivotCache. However, I am having difficulty in getting it to work. Attached is the relevant code:
<code>
Dim cobj As Chart
Set cobj = Me ' "Me" holds a reference to the relevant PivotTable chart
' Added explicit additions, just to be sure
With cobj
.HasAxis(xlValue, xlPrimary) = True
.HasAxis(xlValue, xlSecondary) = True
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlCategory, xlSecondary) = True
End With
Dim rngMilestones As Range ' Holds a Range object with the new series data (date/description pairs)
Dim marker_series As Series
Set marker_series = cobj.SeriesCollection.Add(Source:=rngMilestones, Rowcol:=xlRows, SeriesLabels:=True, CategoryLabels:=False, Replace:=True)
marker_series.AxisGroup = xlSecondary
marker_series.ChartType = xlLine
' Clean up
Set marker_series = Nothing
Set cobj = Nothing
</code>
All of the PivotChart data lies on the xlPrimary axis. I receive a run-time error #1004: Unable to get the Add property of the SeriesCollection class. Little help as to how one can add a secondary axis to a PivotChart using VBA? Please let me know if additional detail regarding the chart characteristics are needed.
Thanks!
I am attempting to add a series on the xlSecondary axis of a PivotChart of BarStacked type. Please note that the data for the other series is not contained within the underlying PivotTable/ PivotCache. However, I am having difficulty in getting it to work. Attached is the relevant code:
<code>
Dim cobj As Chart
Set cobj = Me ' "Me" holds a reference to the relevant PivotTable chart
' Added explicit additions, just to be sure
With cobj
.HasAxis(xlValue, xlPrimary) = True
.HasAxis(xlValue, xlSecondary) = True
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlCategory, xlSecondary) = True
End With
Dim rngMilestones As Range ' Holds a Range object with the new series data (date/description pairs)
Dim marker_series As Series
Set marker_series = cobj.SeriesCollection.Add(Source:=rngMilestones, Rowcol:=xlRows, SeriesLabels:=True, CategoryLabels:=False, Replace:=True)
marker_series.AxisGroup = xlSecondary
marker_series.ChartType = xlLine
' Clean up
Set marker_series = Nothing
Set cobj = Nothing
</code>
All of the PivotChart data lies on the xlPrimary axis. I receive a run-time error #1004: Unable to get the Add property of the SeriesCollection class. Little help as to how one can add a secondary axis to a PivotChart using VBA? Please let me know if additional detail regarding the chart characteristics are needed.
Thanks!