Add a series on the secondary axis in a PivotChart

mill

New Member
Joined
Mar 29, 2007
Messages
13
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!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,206
Messages
6,123,638
Members
449,109
Latest member
Sebas8956

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