Delete multiple chartobjects from one chart sheet

userkjay

New Member
Joined
Aug 24, 2011
Messages
10
The objective: Use VBA to delete multiple chartobjects from one chart sheet.

If multiple chartobjects are created on one chart using the following code:

Code:
[FONT=Arial]Sub ChartCreate()[/FONT]
[FONT=Arial]Dim chtTemp  As ChartObject[/FONT]
[FONT=Arial]Charts.Add.Location Where:=xlLocationAsNewSheet, Name:="My Chart"[/FONT]
[FONT=Arial]For j = 1 To 3[/FONT]
[FONT=Arial]   Set chtTemp = Charts("My Chart").ChartObjects.Add(4 ^ j, 4 ^ j, 10, 10)[/FONT]
[FONT=Arial]Next[/FONT]
[FONT=Arial]MsgBox Charts("My Chart").ChartObjects.Count[/FONT]
[FONT=Arial]End Sub[/FONT]

The 3 chartobjects on the chart “My Chart” can be selected with the mouse and deleted by hitting the delete key. I can not duplicate this using VBA. I have tried the macro recorder, but it does not capture the delete command. I have tried using sendkeys, with no success. One of the many methods of VBA code that I have tried is below:

Code:
[FONT=Arial]Sub ChartDelete()[/FONT]
[FONT=Arial]For i = 1 To ActiveChart.ChartObjects.Count[/FONT]
[FONT=Arial]   ActiveChart.ChartObjects(ActiveChart.ChartObjects(i).Name).Delete[/FONT]
[FONT=Arial]Next[/FONT]
[FONT=Arial]End Sub[/FONT]

If anyone knows of a work around it would be greatly appreciated. I have found this problem to be a challenge.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top