Table of Contents
Using VBA (Visual Basic for Applications), it is possible to delete charts from a spreadsheet. To do this, you can use the ActiveSheet.ChartObjects.Delete method, which will delete all charts on the active worksheet. You can also use the .Delete method on a single chart object if you only want to delete one chart. Examples of these methods are provided to help illustrate how to use them.
You can use the following methods in VBA to delete charts in Excel:
Method 1: Delete All Charts on Active Sheet
Sub DeleteActiveSheetCharts()
ActiveSheet.ChartObjects.Delete
End Sub
This particular macro will delete all charts from the currently active sheet in Excel.
Method 2: Delete All Charts in Entire Workbook
Sub DeleteAllWorkbookCharts()
Dim wk As Worksheet
For Each wk In Worksheets
If wk.ChartObjects.Count > 0 Then
wk.ChartObjects.Delete
End If
Next wk
End Sub
This particular macro will delete all charts from every sheet in the entire Excel workbook.
The following examples show how to use each method in practice.
Example 1: Delete All Charts on Active Sheet
Suppose we have the following sheet in Excel that contains two charts:
We can create the following macro to delete all of the charts from this sheet:
Sub DeleteActiveSheetCharts()
ActiveSheet.ChartObjects.Delete
End Sub
When we run this macro, we receive the following output:
Notice that both charts have been deleted from the sheet.
Example 2: Delete All Charts in Entire Workbook
We can create the following macro to delete all charts from both sheets in the workbook:
Sub DeleteAllWorkbookCharts()
Dim wk As Worksheet
For Each wk In Worksheets
If wk.ChartObjects.Count > 0 Then
wk.ChartObjects.Delete
End If
Next wk
End Sub
Once we run this macro, all charts from both sheets will be deleted:
Note that in this example we only deleted charts from two sheets but this macro will work with an Excel workbook with any number of sheets.