Thursday, January 23, 2025
No menu items!
HomeData Analytics and VisualizationVBA : How to Delete Charts in Excel

VBA : How to Delete Charts in Excel

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.

VBA : Remove specific chart

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

VBA : Remove specific chart in Excel
Task 2 : Delete all charts in a sheet

Let’s take a sample data to understand the process.

VBA : Delete all charts in a sheet
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

VBA : Delete all charts in a sheet
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.

VBA: Delete all charts in an Excel Workbook
VBA: Delete all charts in a workbook
VBA: Delete all charts in a workbook
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

VBA: Delete all charts in an Excel Workbook
VBA: Delete all charts in a workbook
VBA: Delete all charts in a workbook

Read MoreListenData

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments