Microsoft Office Tutorials and References
In Depth Information
Deleting from the ChartObjects or Charts Collection
Deleting from the ChartObjects or Charts Collection
To delete a chart on a worksheet, you must know the name or index of the ChartObject or the
Shape object. This statement deletes the ChartObject named Chart 1 on the active worksheet:
ActiveSheet.ChartObjects(“Chart 1”).Delete
To delete all ChartObject objects on a worksheet, use the Delete method of the ChartObjects
collection:
ActiveSheet.ChartObjects.Delete
You can also delete embedded charts by accessing the Shapes collection. The following
statement deletes the shape named Chart 1 on the active worksheet:
ActiveSheet.Shapes(“Chart 1”).Delete
This code deletes all embedded charts (and all other shapes) on the active sheet:
Dim shp as Shape
For Each shp In ActiveSheet.Shapes
shp.Delete
Next shp
To delete a single chart sheet, you must know the chart sheet’s name or index. The following
statement deletes the chart sheet named Chart1 :
Charts(“Chart1”).Delete
To delete all chart sheets in the active workbook, use the following statement:
ActiveWorkbook.Charts.Delete
Deleting sheets causes Excel to display a warning like the one shown in Figure 18-3. The user
must reply to this prompt in order for the macro to continue. If you’re deleting a sheet with a
macro, you probably won’t want this warning prompt to appear. To eliminate the prompt, use the
following series of statements:
Application.DisplayAlerts = False
ActiveWorkbook.Charts.Delete
Application.DisplayAlerts = True
 
Search JabSto ::




Custom Search