I've got a relatively big amount of data which I want to put in graphs.
Basically, what I have is multiple components (in total 30-ish but in the example below I'll limit the code to 5 components), and each component has one column. I've assigned the column numbers to the respective components, declared as integers. Sometimes I don't want a component to have a graph so that's where there's a gap in the numbers (e.g. in between diat and hydr is another component in column 5 but for this one there shouldn't be a graph).
Then I wanted to put all the components of which I want a graph into one array and do a For... Next loop so a graph would be automatically created for each element in the array (so for each component in the array).
Obviously I did something wrong :-). The code gets stuck on the first time I try to refer to the respected element in the array: ActiveChart.SeriesCollection(1).Name = Cells(9, componentlist(1, i))
Dim diat, hydr, para, terb, theo As Integer
diat = 4 'column number of the component named diat
hydr = 6 'column number of the component named hydr
para = 7 'column number of the component named para
terb = 9 'column number of the component named terb
theo = 10 'column number of the component named theo
Dim componentlist As Variant
componentlist = Array(diat, hydr, para, terb, theo)
For i = 1 To UBound(componentlist)
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SeriesCollection.NewSeries.Select
ActiveChart.SeriesCollection(1).Name = Cells(9, componentlist(1, i))
ActiveChart.SeriesCollection(1).XValues = Worksheets(2).Range(Cells(10, 3), Cells(21, 3))
ActiveChart.SeriesCollection(1).Values = Worksheets(2).Range(Cells(10, componentlist(1, i)), Cells(21, componentlist(1, i)))
Next
My experience with VBA is limited so does anyone of you know how to solve this? Thanks in advance!