ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Chart Objects Error (https://www.excelbanter.com/excel-programming/342691-chart-objects-error.html)

Bill[_30_]

Chart Objects Error
 
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

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

Vic Eldridge[_3_]

Chart Objects Error
 
Hi Bill,

The simplest way would have to be ActiveSheet.ChartObjects.Delete

Regards,
Vic Eldridge



"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





All times are GMT +1. The time now is 03:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com