I cannot figure out how to delete charts with VBA.
Starting Point:
- Create Blank Workbook
- Press F11 three times to create
Chart1
,Chart2
, andChart3
- Right-click in
Chart2
, Move Chart, Object in:Chart 1
- Right-click in
Chart3
, Move Chart, Object in:Chart 1
What VBA code will delete all charts (Chart2
and Chart3
) from Chart1
?
Attempts:
'Try 1: Run-time error -2147024809 (80070057):
' The specified value is out of range.
Sheets("Chart1").ChartObjects.Delete
'Try 2: (Same error)
Charts("Chart1").ChartObjects.Delete