Troubles with asigning x values and values to a chart
The following code returns run-time error 1004 with message:
Method'SeriesCollection' of object '_Chart' failed. It stops on:
ActiveChart.SeriesCollection(k).XValues = rngX
I tried already many ways of building this, but it stil doesn't work.
The code inside pharentesis: Range( .. ) returns proper value
"A7:A2407" (which are not empty) and PreformName(i) returns proper
value.
The motivation for this code is analysing mesurement data, which is set
in A and B colmun. In EmptyIndex there are positions of empty spaces
between mesurements.
Help me please
For k = 1 To (UBound(EmptyIndex) - 1)
rngX = Worksheets(PreformName(i)).Range("A" &
(EmptyIndex(k) + 3) & ":A" & EmptyIndex(k + 1))
rngVal = Worksheets(PreformName(i)).Range("B" &
(EmptyIndex(k) + 3) & ":B" & EmptyIndex(k + 1))
rngName = Worksheets(PreformName(i)).Range("A5")
ActiveChart.SeriesCollection(k).XValues = rngX
ActiveChart.SeriesCollection(k).Values = rngVal
ActiveChart.SeriesCollection(k).Name = rngName
With ActiveChart.SeriesCollection(k).Border
.ColorIndex = ColorInd
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With ActiveChart.SeriesCollection(k)
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = True
.MarkerSize = 3
.Shadow = False
End With
ColorInd = ColorInd + 1
Next k
|