Chart Objects Error
I'm not sure why you have that "exit for", but if you start at the highest
number and work down, it helps:
Nchobj = ActiveSheet.ChartObjects.Count
For i = Nchobj to 1 step -1
ActiveSheet.ChartObjects(i).Delete
Next i
Or if you just delete the first one (delete the first, the second becomes the
new first, etc, etc, etc)
Nchobj = ActiveSheet.ChartObjects.Count
For i = 1 To Nchobj
ActiveSheet.ChartObjects(1).Delete
Next i
Bill wrote:
Hello,
I have two or more chart objects on worksheet that I want to delete before I
rebuild them. I am using the following code to do that:
Nchobj = ActiveSheet.ChartObjects.Count
For i = 1 To Nchobj
ActiveSheet.ChartObjects(i).Delete
Next i
Exit For
The first one deletes OK. The second chart object generates this message:
Unable to get ChartObjects property of the Worksheet class. On debug, it
goes to the activesheet.chartobjects(i).delete line.
Any ideas? Thanks.
Bill
--
Dave Peterson
|