Reputation: 212
I am trying to create a chart with VBA with the following line:
Set StressChart = INFsheet.Shapes.AddChart2(240, xlXYScatterLines)
Sometimes the chart already comes with a (nonsense) datapoint, and I have to delete it:
StressChart.Chart.FullSeriesCollection(1).Delete
However, sometimes there is no data yet, and the FullSeriesCollection object does not exist. This causes an error.
How can I predict if there will be data, or how can I test if there is data?
My locals tree looks as follows:
The snap is taken at the following breakpoint:
The code runs fine as it is shown above, but if un-comment the second green line (marked "Disabled for debug"), I get the following error: "Parameter not valid".
Upvotes: 0
Views: 525
Reputation: 1
To create a diagram without unnecessary rows:
Dim mychart as chart
Set mychart=activesheet.chartobjects.add(10,10,300,200)
With mychart.seriescollection.newseries
.XValues=range(cells(1,10), cells(5,10))
.Values=range(cells(1,11), cells(5,11))
End with
Upvotes: 0
Reputation: 42236
Please, try:
If `StressChart.Chart.FullSeriesCollection.count > 0 Then StressChart.Chart.FullSeriesCollection(1).Delete`
Edited: Using the above suggestion in your code as:
If `.Chart.FullSeriesCollection.count > 0 Then .Chart.FullSeriesCollection(1).Delete`
does it rise the same error?
Upvotes: 1