Delete multiple chartobjects from one chart sheet

Aug 24, 2011
Reaction score
The objective: Use VBA to delete multiple chartobjects from one chart sheet.

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

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

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. The VBA code that I have tried is below:

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

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


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question