Hi,
I have encountered the following problem:
I have a huge set of data (experimental measurements), which I have gathered to Excel so, that the data I'd like to plot in a graph is in every 8th column (first data series I'd like to plot is A30:B50, second I30:J80, third Q30:R70, and so on). I have managed to write a code that is working, but has each column in the code separately. Because I have to occasionally change the code, I'd like to write it using a loop so it'd be easier to modify. And that's where I seem to fail. This is my attempt:
The result of running this code is that I get a run-time error saying "A chart can only have up to 256 series" and the graph I get is filled with 256 empty series.
Any help would be appreciated!
I have encountered the following problem:
I have a huge set of data (experimental measurements), which I have gathered to Excel so, that the data I'd like to plot in a graph is in every 8th column (first data series I'd like to plot is A30:B50, second I30:J80, third Q30:R70, and so on). I have managed to write a code that is working, but has each column in the code separately. Because I have to occasionally change the code, I'd like to write it using a loop so it'd be easier to modify. And that's where I seem to fail. This is my attempt:
Code:
'to loop through columns
For i = ActiveSheet.Range("a30") To ActiveSheet.Range("eg30") Step 8 'if the first cell of the range is a certain value I want to exclude it from the graph
For j = ActiveSheet.Range("f12").Column To ActiveSheet.Range("el12").Column Step 8 'the series names
For k = ActiveSheet.Range("A30", Range("A30").End(xlDown)).Column To ActiveSheet.Range("eg30", Range("eg30").End(xlDown)).Column Step 8 'series x values if first cell of range is not excluded
For l = ActiveSheet.Range("b30", Range("b30").End(xlDown)).Column To ActiveSheet.Range("eh30", Range("eh30").End(xlDown)).Column Step 8 'series y values if first cell of range is not excluded
For m = ActiveSheet.Range("A31", Range("A31").End(xlDown)).Column To ActiveSheet.Range("eg31", Range("eg31").End(xlDown)).Column Step 8 'series x values if first cell of range is excluded
For n = ActiveSheet.Range("b31", Range("b31").End(xlDown)).Column To ActiveSheet.Range("eh31", Range("eh31").End(xlDown)).Column Step 8 'series y values if first cell of range is excluded
'DATA SERIES
'If first cell in the range equals 0.2, -0.2, 0.3 or -0.3 then I want to EXCLUDE that data pair.
'In the code it looks as if I've written it the wrong way around
'(if first cell equals 0.2 fx, then the code says to include it in the range, although that's the opposite to what I want as an outcome),
'but the code does what I want --> makes no sense, I know, but somehow it works.
If (i) = ("0.2") Or (i) = ("-0.2") Or (i) = ("0.3") Or (i) = ("-0.3") Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = (j)
ActiveChart.FullSeriesCollection(1).XValues = (k)
ActiveChart.FullSeriesCollection(1).Values = (l)
Else
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = (j)
ActiveChart.FullSeriesCollection(1).XValues = (m)
ActiveChart.FullSeriesCollection(1).Values = (n)
Exit For
End If
Next n
Next m
Next l
Next k
Next j
Next i
Any help would be appreciated!