У меня есть следующий код
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("Graphs")
Dim chrt As Chart
Set chrt = sh.Shapes.AddChart.Chart
Set s1 = chrt.SeriesCollection.NewSeries
Set s2 = chrt.SeriesCollection.NewSeries
Set s3 = chrt.SeriesCollection.NewSeries
Set s4 = chrt.SeriesCollection.NewSeries
Set s5 = chrt.SeriesCollection.NewSeries
With s1
.ChartType = xlXYScatterLines
'Change to what your series should be called
.Name = "ConcreteCS"
.XValues = "=Graphs!$E$48:$E$52"
.Values = "=Graphs!$F$48:$F$52"
End With
With s2
.ChartType = xlXYScatter
.Name = "Asl_base_corner"
.XValues = "=Graphs!$K$48:$K$49"
.Values = "=Graphs!$L$48:$L$49"
End With
With s3
.ChartType = xlXYScatter
.Name = "Asl_base_mid"
.XValues = "=Graphs!$K$52:$k$100"
.Values = "=Graphs!$L$52:$L$100"
End With
With s4
.ChartType = xlXYScatter
.Name = "Asl_add_corner"
.XValues = "=Graphs!$Q$48:$Q$49"
.Values = "=Graphs!$R$48:$R$49"
End With
With s5
.ChartType = xlXYScatter
.Name = "Asl_add_mid"
.XValues = "=Graphs!$Q$52:$Q$100"
.Values = "=Graphs!$R$52:$R$100"
End With
With chrt
.ChartArea.Left = 100
.ChartArea.Top = 750
.ChartArea.Height = 200
.ChartArea.Width = 200
.Axes(xlValue).MajorGridlines.Delete
.HasAxis(xlCategory, xlPrimary) = False
.HasAxis(xlCategory, xlSecondary) = False
.HasAxis(xlValue, xlPrimary) = False
.HasAxis(xlValue, xlSecondary) = False
.Axes(xlCategory).MinimumScale = -b / 2
.Axes(xlCategory).MaximumScale = b + b / 2
.Axes(xlValue).MinimumScale = -h / 2
.Axes(xlValue).MaximumScale = h + h / 2
For ii = 1 To chrt.Legend.LegendEntries.Count Step 1
.Legend.LegendEntries(ii).Delete
Next
End With
Но результат - разброс с линиями для s1, s2 и s3 и разброс для s4 и s5. Странно то, что я определил scatter только со строками для s1. Кроме того, когда я пытаюсь удалить легенды для всех серий, из индекса 4 до 5 выдает ошибку, хотя индекс существует (chrt.Legend.LegendEntries.Count = 5).
Пожалуйста, помогите мне !!! :)
Большое спасибо