chart series: displaying the source range

R

R Vaughn

I am trying to set up a message box that will display the source range for a
series in a line graph. I get a "Run-time error 438" with the following
code. What is wrong?

ChartObjects(1).Select
x = ChartObjects(1).SeriesCollection(5).Values
MsgBox (x)
 
S

smartin

R said:
I am trying to set up a message box that will display the source range for a
series in a line graph. I get a "Run-time error 438" with the following
code. What is wrong?

ChartObjects(1).Select
x = ChartObjects(1).SeriesCollection(5).Values
MsgBox (x)

This will display the value portion of the series:

Sub Lime()
Dim co As ChartObject
Dim sc As SeriesCollection
Set co = ActiveSheet.ChartObjects(1)
Set sc = co.Chart.SeriesCollection
Debug.Print sc(5).Formula
' the series' value range is:
MsgBox Split(sc(5).Formula, ",")(2)
Stop
End Sub

FYI The Values property is an array, so you can't display it as a string
without some treatment.

Formula is a string, but I treat it like a comma-delimited array (see
the output in the debug window). The "value" portion of the Formula
"array" is member 2 because Split returns a zero-based array.
 
R

R Vaughn

Thank you for your help.


smartin said:
This will display the value portion of the series:

Sub Lime()
Dim co As ChartObject
Dim sc As SeriesCollection
Set co = ActiveSheet.ChartObjects(1)
Set sc = co.Chart.SeriesCollection
Debug.Print sc(5).Formula
' the series' value range is:
MsgBox Split(sc(5).Formula, ",")(2)
Stop
End Sub

FYI The Values property is an array, so you can't display it as a string
without some treatment.

Formula is a string, but I treat it like a comma-delimited array (see
the output in the debug window). The "value" portion of the Formula
"array" is member 2 because Split returns a zero-based array.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top