How to delete a pivot table in vba

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to delete a pivot table in vba
Learn how to delete a pivot table using Visual Basic for Applications. (background with binary data image by Pedro Nogueira from Fotolia.com)

A pivot table is used to summarise data and is commonly used in spreadsheet programs such as Microsoft Excel. Visual Basic for Applications is a computer programming language developed by Microsoft and used to automate routine tasks in Microsoft Office applications. You may need to write VBA code to delete pivot tables if you have a workbook with a lot of worksheets and you need to manually delete them. In a few steps you may write VBA code to delete a pivot table.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    Start Microsoft Office Excel and type "Columns" in "A1", "Data" in "B1", "Field" in "A2", "12" in "B2", "Field2" in "A3", and "13" in "B3".

    Click "A1", press "Ctrl" and "A," click the "Insert" menu and select "PivotTable." Click "OK."

  2. 2

    Check the boxes next to "Columns" and "Data."

    Select the "Developer" tab, then click "Visual Basic." Click the "Insert" menu and select "Module."

  3. 3

    Copy and paste the code below into your new module to delete the pivot table you have just created.

    Private Sub deletePivotTable()

    Dim Ptbl As PivotTable
    
    Dim wrkSheet As Worksheet
    
         For Each wrkSheet In ActiveWorkbook.Worksheets
    
         For Each Ptbl In wrkSheet.PivotTables
    
            Range("A3:B6").Select
    
            Selection.Delete Shift:=xlToLeft
    
            Range("A1").Select
    
            Exit Sub
    
        Next Ptbl
    
    Next wrkSheet
    

    End Sub

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.