How to Delete One or All Pivot Tables in Excel


Pivot tables are a useful tool in Microsoft Excel that lets you easily analyse and summarise massive amounts of data. However, there may be times when you need to delete a pivot table from your worksheet, either to make room or to begin a new study. In this tutorial, we will show you how to delete a single pivot table or all pivot tables from your Excel spreadsheet.

Whether you're new to Excel or an experienced user, this post will show you how to delete pivot tables in a basic and clear manner. By the end of this course, you will be confident and knowledgeable about removing pivot tables from Excel worksheets. So, let's get started and figure out how to delete pivot tables in Excel!

Deleting All Pivot Tables in Excel

Here we will use the VBA application to complete the task. So let us see a simple process to learn how you can delete all pivot tables in Excel.

Step 1

Consider any Excel sheet where you have multiple pivot tables.

First, right−click on the sheet name and select "View Code" to open the VBA application.

Right click > View code.

Step 2

Then click on Insert, select Module, and copy the below code into the text box.

Insert > Module > Copy.

Example

Sub DeleteAllPivotTablesInWorkbook()
Dim xWs As Worksheet
Dim xPT As PivotTable
For Each xWs In Application.ActiveWorkbook.Worksheets
    For Each xPT In xWs.PivotTables
        xWs.Range(xPT.TableRange2.Address).Delete Shift:=xlUp
    Next
Next
End Sub

Step 3

Then click F5 to run the code to complete the task.

Note:If you want to delete only one pivot table, use the below code.

Sub DeletePivotTable()
    Dim pt As PivotTable
    
    Set pt = ThisWorkbook.Sheets("Sheet1").PivotTables("PivotTable1")
    
    pt.TableRange2.Clear ' Clear the data and formatting associated with the pivot table
    pt.PivotCache.Clear ' Clear the pivot cache
    pt.Delete ' Delete the pivot table object
End Sub

In the code, Sheet1 and PivotTable1 are names of sheet and pivot table, respectively.

Conclusion

In this tutorial, we have used a simple example to demonstrate how you can delete one or all pivot tables in Excel to highlight a particular set of data.

Updated on: 20-Jul-2023

86 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements