The objective: Use VBA to delete multiple chartobjects from one chart sheet.
If multiple chartobjects are created on one chart using the following code:
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:
If anyone knows of a work around it would be greatly appreciated. I have found this problem to be a challenge.
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.