Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

Simple Sub Delete Pivot Table "PTableName":

Sub Test()
Dim WB As Workbook, WS As Worksheet, PT As PivotTable

Set WB = ThisWorkbook
Set WS = WB.Worksheets("PivotTable")
Set PT = WS.PivotTables("PTableName")
WS.Range(PT.TableRange2.Address).Delete
'ActiveWorkbook.ActiveSheet.Range(ActiveWorkbook.ActiveSheet.PivotTables("PTableName").TableRange2.Address).Delete
End Sub

Sub to Delete PivotTable w/ Sheet & Table Name As Arguments:

Sub DeletePivotTable(ptName As String, SheetName As String)
Dim WB As Workbook, WS As Worksheet, PT As PivotTable

Set WB = ThisWorkbook
Set WS = WB.Worksheets(SheetName)
Set PT = WS.PivotTables(ptName)

WS.Range(PT.TableRange2.Address).Delete

End Sub

Sub Test()
 Call DeletePivotTable("PTableName", "PivotTable")
End Sub

  • No labels