This tutorial explains how to remove one or multiple charts in Excel using VBA. It includes various practical examples covering everything related to deleting charts in Excel.
Task 1 : Remove a specific chart
Using the Workbook Name
, Sheet Name
and Chart Name
it can be achieved. Let’s take an example to undersatnd this.
Statement : Remove Chart-2 from Sheet1 which belongs to Book4.
Sub RemoveChartByName() Workbooks("Book4").Sheets("Sheet1").ChartObjects("Chart 2").Delete End Sub
Click the chart and see the
Name Box
to get the chart name.Press Run or F5 to run the above code.
The result looks like this
Task 2 : Delete all charts in a sheet
Let’s take a sample data to understand the process.
Sub DeleteAllCharts() Dim ChartObject As ChartObject For Each ChartObject In ActiveSheet.ChartObjects ChartObject.Delete Next ChartObject End Sub
Press Run or F5 to run the above code
The result looks like this
Task 3 : Delete all charts in a workbook
Consider a workbook Book-1
which consists of
three sheets i.e. Sheet 1
, Sheet 2
, and Sheet 3
. All of these contain some charts as data.
Sub DeleteAllChartsInWorkbook() Dim ws As Worksheet Dim ChartObject As ChartObject For Each ws In ThisWorkbook.Sheets For Each ChartObject In ws.ChartObjects ChartObject.Delete Next ChartObject Next ws End Sub
Press Run or F5 to run this code.
The result looks like this
Read MoreListenData