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:
Sub ChartCreate()
Dim chtTemp As ChartObject
Charts.Add.Location Where:=xlLocationAsNewSheet, Name:="My Chart"
For j = 1 To 3
Set chtTemp = Charts("My Chart").ChartObjects.Add(4 ^ j, 4 ^ j, 10, 10)
Next
Msgbox Charts("My Chart").ChartObjects.Count
End Sub
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:
Code:
Sub ChartDelete()
For i = 1 To ActiveChart.ChartObjects.Count
ActiveChart.ChartObjects(ActiveChart.ChartObjects(i).Name).Delete
Next
End Sub
If anyone knows of a work around it would be greatly appreciated. I have found this problem to be a challenge.