M
Mika
Hi,
I have the following VBA code for Excel 97.
I have also one problem. When I use
ActiveChart.SeriesCollection.NewSeries, Excel will add a new legend
entry. When I use Trendlines.Add, Excel will add another one. How can I
add only the second one?
And the code...
ActiveSheet.ChartObjects("Chart 1").Activate
'Delete old data series (maybe this could be done easier?)
For i = 20 To 1 Step -1
Err.Clear
ActiveChart.SeriesCollection(i).Delete
Err.Clear
Next i
Err.Clear
'Columns 1-20
For i = 1 To 20
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "=Sheet1!R2C1:R20C1"
ActiveChart.SeriesCollection(i).Values = "=Sheet1!R2C" & i + 1 &
":R20C" & i + 1
ActiveChart.SeriesCollection(i).Name = "=Sheet1!R1C" & i + 1
'Hide diagram
ActiveChart.SeriesCollection(i).Select
With Selection.Border
.Weight = xlThick
.LineStyle = xlNone
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
'Add trendline
ActiveChart.SeriesCollection(i).Select
ActiveChart.SeriesCollection(i).Trendlines.Add(Type:=xlMovingAvg,
Period:=144, Forward:=0, Backward:=0, DisplayEquation:=False,
DisplayRSquared:=False).Select
ActiveChart.SeriesCollection(i).Trendlines(1).Select
With Selection.Border
.ColorIndex = 40 + i
.Weight = xlThick
.LineStyle = xlContinuous
End With
With Selection
.Type = xlMovingAvg
.Period = 200
.Forward = 0
.Backward = 0
.InterceptIsAuto = True
.DisplayEquation = False
.DisplayRSquared = False
.Name = InputBox("String:", "Name of serie " & i,
ActiveChart.SeriesCollection(i).Name)
End With
Next i
I have the following VBA code for Excel 97.
I have also one problem. When I use
ActiveChart.SeriesCollection.NewSeries, Excel will add a new legend
entry. When I use Trendlines.Add, Excel will add another one. How can I
add only the second one?
And the code...
ActiveSheet.ChartObjects("Chart 1").Activate
'Delete old data series (maybe this could be done easier?)
For i = 20 To 1 Step -1
Err.Clear
ActiveChart.SeriesCollection(i).Delete
Err.Clear
Next i
Err.Clear
'Columns 1-20
For i = 1 To 20
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "=Sheet1!R2C1:R20C1"
ActiveChart.SeriesCollection(i).Values = "=Sheet1!R2C" & i + 1 &
":R20C" & i + 1
ActiveChart.SeriesCollection(i).Name = "=Sheet1!R1C" & i + 1
'Hide diagram
ActiveChart.SeriesCollection(i).Select
With Selection.Border
.Weight = xlThick
.LineStyle = xlNone
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlNone
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
'Add trendline
ActiveChart.SeriesCollection(i).Select
ActiveChart.SeriesCollection(i).Trendlines.Add(Type:=xlMovingAvg,
Period:=144, Forward:=0, Backward:=0, DisplayEquation:=False,
DisplayRSquared:=False).Select
ActiveChart.SeriesCollection(i).Trendlines(1).Select
With Selection.Border
.ColorIndex = 40 + i
.Weight = xlThick
.LineStyle = xlContinuous
End With
With Selection
.Type = xlMovingAvg
.Period = 200
.Forward = 0
.Backward = 0
.InterceptIsAuto = True
.DisplayEquation = False
.DisplayRSquared = False
.Name = InputBox("String:", "Name of serie " & i,
ActiveChart.SeriesCollection(i).Name)
End With
Next i