Search code examples
vbaexceldiagram

Creating Dynamic Diagrams via VBA


I tried to create dynamic diagrams with VBA today. The Code itself works fine but ive got the problem that the line-diagram only shows 10 out of 21 data series. The code itself adds 21 Data series via the .NewSeries but when the code is finished the diagram only shows 10 of them. Does anybody has an idea why this happens or has a solution for my problem?

ActiveSheet.Shapes.AddChart2(, xlLine, 0, 0, 1400).Select
Dim cht As Chart
Set cht = ActiveChart
cht.HasLegend = True
cht.ChartTitle.Text = "Test"
    With ActiveChart
    Do Until .SeriesCollection.Count = 0
        .SeriesCollection(1).Delete
    Loop
End With  
For i = 2 To clmns Step 4
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(cnt).Name = Worksheets(1).Cells(1, i)
ActiveChart.FullSeriesCollection(cnt).Values = Worksheets(1).Range(Worksheets(1).Cells(1, i), Worksheets(1).Cells(rws, i))
cnt = cnt + 1
Next

Greetings Benjamin


Solution

  • I just got the Solution, it was just a display bug, excel did not noticed that there are that many data series. I just adjusted the width and height a little bit and it refreshed the diagram and all series were there. Thank you.