Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

activechartseriescollectionindex

Forum home » Delegate support and help forum » Microsoft Excel Training and help » ActiveChart.SeriesCollection(index) index as a function

ActiveChart.SeriesCollection(index) index as a function

ResolvedVersion 2007

jeff has attended:
Excel VBA Intro Intermediate course

ActiveChart.SeriesCollection(index) index as a function

Hi I have two questions:
1.) Is it possible to have the index part of an ActiveChart.SeriesCollection(index) as a function i.e. "n + 1" or a integer or variable that is equal to a function. I have a VBA script that uses for loops to add series's of data to a chart through the script. I think I will be able to simplify my script if I can do this.

2.) The plot is an xy scatter and I would like the values of the dataseries to be a collection of points that are not all next to each other. is this possible? I have found a work around by creating an array from the values but ideally the char would be pointing at the cells in the sheet.

I hope I have explained my questions clearly.

Thanks very much in advance.

Script below

Sub CreateChartScript()

Dim n As Integer
Dim t As Integer
Dim j As Integer

ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
For n = 1 To 7 'fixed for 7 columns, 10 to 70 deg C, if adding more columns adjust.
ActiveChart.SeriesCollection.NewSeries
With ActiveChart.SeriesCollection(n)
.MarkerStyle = xlMarkerStyleNone
.Border.ColorIndex = 1
.Border.Weight = xlThin
.Name = Sheets("Cont RH").Cells(1, 2 + n)
.XValues = Range(Sheets("Cont RH").Cells(2, 2), Sheets("Cont RH").Cells(16, 2))
.Values = Range(Sheets("Cont RH").Cells(2, 2 + n), Sheets("Cont RH").Cells(16, 2 + n))

End With
Next

For n = n To 9 '2 loops
ActiveChart.SeriesCollection.NewSeries
With ActiveChart.SeriesCollection(n)
.MarkerStyle = xlMarkerStyleNone
.Border.ColorIndex = n
.Border.Weight = xlThin
.Name = n 'ActiveSheet.Cells(2, 2)
.XValues = Array(Sheets("Populated sheet").Cells(3 + (n - 7), 2), Sheets("Populated sheet").Cells(6 + (n - 7), 2), Sheets("Populated sheet").Cells(9 + (n - 7), 2))
.Values = Array(Sheets("Populated sheet").Cells(3 + (n - 7), 3), Sheets("Populated sheet").Cells(6 + (n - 7), 3), Sheets("Populated sheet").Cells(9 + (n - 7), 3))

End With
Next

For n = n To 11 '2 loops
ActiveChart.SeriesCollection.NewSeries
With ActiveChart.SeriesCollection(n)
.MarkerStyle = xlMarkerStyleNone
.Border.ColorIndex = n
.Border.Weight = xlThin
.Name = n 'ActiveSheet.Cells(2, 2)
.XValues = Array(Sheets("Populated sheet").Cells(3 + (n - 9), 4), Sheets("Populated sheet").Cells(6 + (n - 9), 4), Sheets("Populated sheet").Cells(9 + (n - 9), 4))
.Values = Array(Sheets("Populated sheet").Cells(3 + (n - 9), 5), Sheets("Populated sheet").Cells(6 + (n - 9), 5), Sheets("Populated sheet").Cells(9 + (n - 9), 5))

End With
Next

With ActiveChart
.Axes(xlCategory).MinimumScale = 0
.Axes(xlCategory).MaximumScale = 100
.Axes(xlCategory).MajorUnit = 10

.Axes(xlValue).MinimumScale = -40
.Axes(xlValue).MaximumScale = 100
.Axes(xlValue).MajorUnit = 10

.SetElement (msoElementChartTitleCenteredOverlay)
.ChartTitle.Text = "test"
End With
End Sub

RE: ActiveChart.SeriesCollection(index) index as a function

Hi Jeff

With regards to your post we have had a look at it and addressing it in 2 parts:

1) Much of what you are trying to do is covered on our Excel VBA Advanced course, click here for details.

2) We can assist with this but will need to see your working files to advise on a solution and amount of work involved.

It is possible to create a bespoke one-to-one training event for you to be trained to develop a solution for your current requirements and enable you to tackle future requirements as well.

Your requests in this instance are beyond the scope of the forum however if you wish to discuss the above options further please reply to my email directly.

Kind regards
Jacob

Excel tip:

Hiding and unhiding columns using the keyboard

CTRL + 0 hides your columns and CTRL + SHIFT + ) unhides them although you would need to highlight the column letters either side as per normal

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.