some clarification of the chart object model

TomCon

Active Member
Joined
Mar 31, 2011
Messages
373
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
If i add a series to a chart, this is recorded.
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""foo"""
ActiveChart.FullSeriesCollection(2).XValues = "=goal!$S$1116:$S$1124"
ActiveChart.FullSeriesCollection(2).Values = "=goal!$T$1116:$T$1125"

Right after doing that, if i go to the immediate window and try to query what those properties are, i get errors.
First this proves that my focus, etc is correct.
?activechart.FullSeriesCollection("foo").Name
foo

But, both of these just give "Type mismatch"
?activechart.FullSeriesCollection("foo").XValues
?activechart.FullSeriesCollection("foo").Values

have tried some variations as well (just "SeriesCollection" or just "Series") but i cannot find a way to get returned to me the property values for the series for properties "Values" and "XValues".

So, how can i write code to query the existing object properties and return to me the XValues and Values property for a series?

Thank you!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
?activechart.FullSeriesCollection("foo").XValues

The above returns an array of values, which can be confirmed with the following....

VBA Code:
? typename(activechart.FullSeriesCollection("foo").xvalues)

To return the first value from the array...

VBA Code:
? activechart.FullSeriesCollection("foo").xvalues()(1)

To loop through each item in the array...

VBA Code:
    Dim xval As Variant
    For Each xval In ActiveChart.FullSeriesCollection("foo").XValues
        Debug.Print xval
    Next

or

VBA Code:
    Dim arr() As Variant
    arr() = ActiveChart.FullSeriesCollection("foo").XValues
    
    Dim arrayIndex As Long
    For arrayIndex = LBound(arr) To UBound(arr)
        Debug.Print arr(arrayIndex)
    Next arrayIndex

And the same thing applies to ?activechart.FullSeriesCollection("foo").Values.

Hope this helps!
 
Upvote 0
The above returns an array of values, which can be confirmed with the following....

VBA Code:
? typename(activechart.FullSeriesCollection("foo").xvalues)

To return the first value from the array...

VBA Code:
? activechart.FullSeriesCollection("foo").xvalues()(1)

To loop through each item in the array...

VBA Code:
    Dim xval As Variant
    For Each xval In ActiveChart.FullSeriesCollection("foo").XValues
        Debug.Print xval
    Next

or

VBA Code:
    Dim arr() As Variant
    arr() = ActiveChart.FullSeriesCollection("foo").XValues
   
    Dim arrayIndex As Long
    For arrayIndex = LBound(arr) To UBound(arr)
        Debug.Print arr(arrayIndex)
    Next arrayIndex

And the same thing applies to ?activechart.FullSeriesCollection("foo").Values.

Hope this helps!
Thanks very very much this does explain what is going on.

But my underlying problem remains. Using your loop above, what the array contains is the actual XValues, i.e. numbers, like 0.77058259157597, 5.20855964923763E-02, etc.

It appears to me that for setting the Xvalues property takes a text string that represents a sheet range, but for return, it converts that to an array of values. So, where in the object model is that sheet range stored?

What i am trying to get out of that already existing series is what sheet range the series is getting its data from. When i set the XValues property, i set it to "=goal!$S$1116:$S$1124". So, how can i query some property out of that chart that will tell me "For series foo, the X Values are coming from goal!$S$1116:$S$1124"?

By the way i have tried many many properties of Series, SeriesCollection, and FullSeriesCollection, and cannot find a place that will return that information.

Thanks much if you have any idea about this!
 
Upvote 0
In that case, use the Formula property of the Series object...

VBA Code:
? activechart.FullSeriesCollection("foo").formula

This will return something like this...

VBA Code:
=SERIES(,Sheet3!$A$2:$A$5,Sheet3!$B$2:$B$5,1)

...which you'll need to parse in order to get what you want.
 
Upvote 0
Solution
In that case, use the Formula property of the Series object...

VBA Code:
? activechart.FullSeriesCollection("foo").formula

This will return something like this...

VBA Code:
=SERIES(,Sheet3!$A$2:$A$5,Sheet3!$B$2:$B$5,1)

...which you'll need to parse in order to get what you want.
Yes...thank you very much. I thought i had tried every "reasonable" combination....but i must not have tried that, as it does do what i need. I appreciate your replies very much!
 
Upvote 0
You're very welcome, I'm glad I could help.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,069
Members
449,092
Latest member
ipruravindra

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