[RESOLVED] removing series from chart
Hey all,
I'm having one of those crazy problems where code worked for like 5 minutes, then after no changes, stops working.. ugh
Anyway.. pretty simple. Basically creating a chart, and want to get rid of the initial series that the chart comes with after creation. I have this exact code working in another part of my project, and this code worked fine for a little, then error message saying deletion of series failed.
vb Code:
Set chartLeach = Charts.Add
chartLeach.name = chartName
With chartLeach
If graphStyle = 2 Then
.ChartType = xlColumnClustered
ElseIf graphStyle = 1 Then
.ChartType = xlLine
End If
Do Until .SeriesCollection.count = 0
.SeriesCollection(1).Delete 'FAILING
Loop
End With
Is this bad practice? I'm baffled, especially after this exact code works in other spots of my project...
Thanks much!
Re: removing series from chart
hmm..
restarted the workbook and now it's working again... strange. I'll mark this as resolved, but if anyone has any comments on better practice it would be much appreciated!
Thanks
Re: [RESOLVED] removing series from chart
is that the complete code?
if yes, then the code never enters the if or the Do loop
To Check you can try this
Code:
Sub test()
Set chartLeach = Charts.Add
chartLeach.Name = chartname
With chartLeach
If graphStyle = 2 Then
.ChartType = xlColumnClustered
MsgBox "Entered the loop" '<===============
ElseIf graphStyle = 1 Then
.ChartType = xlLine
MsgBox "Entered the loop" '<===============
End If
Do Until .SeriesCollection.Count = 0
MsgBox "Entered the loop" '<===============
Loop
End With
End Sub
Re: [RESOLVED] removing series from chart
hmm.. yeah it's not the complete code. the graph style is defined earlier and it enters those ifs...
but there is something wierd about the .delete loop b/c it is actually entering it at some points and others not. I gotta do some more testing. b/c I changed from unloading that form to merely hiding it, and now I'm not encountering the problem.