(Solved) – Scatter and Scatter lines dont match obtained results

(solved)-–-scatter-and-scatter-lines-dont-match-obtained-results

I have the following code

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

But the result is scatter with lines for s1, s2 and s3 and scatter for s4 and s5.
The strange thing is that I’ve only defined scatter with lines for s1.
Also, when I try to delete the legends for all series, from index 4 to 5 gives me error, although the index exists (chrt.Legend.LegendEntries.Count = 5).

Please help me!!! 🙂

Many thanks

Leave a Reply

Your email address will not be published. Required fields are marked *