ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete pivot table (https://www.excelbanter.com/excel-programming/348870-delete-pivot-table.html)

HSalim[MVP]

Delete pivot table
 
Hi
What is the syntax to delete a pivottable programatically? I tried

Dim ws As Worksheet
Dim pt As PivotTable

Set ws = ActiveWorkbook.Worksheets("unused")

Set pt = ws.PivotTables(1)
pt.Delete ' error
Set pt = Nothing

Thanks
Habib



Tom Ogilvy

Delete pivot table
 
ws.PivotTables(1).DataBodyRange _
.CurrentRegion.EntireColumn.Delete


or .clearcontents



if there is data below the pivottable



set pt = ws.PivotTables(1)
ws.range(pt.pagerange,pt.databodyrange).Clear



--

Regards,

Tom Ogilvy



"HSalim[MVP]" wrote in message
...
Hi
What is the syntax to delete a pivottable programatically? I tried

Dim ws As Worksheet
Dim pt As PivotTable

Set ws = ActiveWorkbook.Worksheets("unused")

Set pt = ws.PivotTables(1)
pt.Delete ' error
Set pt = Nothing

Thanks
Habib





HSalim[MVP]

Delete pivot table
 
Tom,
Thanks for the quick response. I took your example with a twist -
ws.PivotTables(1).DataBodyRange _
.CurrentRegion.EntireRow.Delete

Regards and Merry Christmas
Habib







"Tom Ogilvy" wrote in message
...
: ws.PivotTables(1).DataBodyRange _
: .CurrentRegion.EntireColumn.Delete
:
:
: or .clearcontents
:
:
:
: if there is data below the pivottable
:
:
:
: set pt = ws.PivotTables(1)
: ws.range(pt.pagerange,pt.databodyrange).Clear
:
:
:
: --
:
: Regards,
:
: Tom Ogilvy
:
:
:
: "HSalim[MVP]" wrote in message
: ...
: Hi
: What is the syntax to delete a pivottable programatically? I tried
:
: Dim ws As Worksheet
: Dim pt As PivotTable
:
: Set ws = ActiveWorkbook.Worksheets("unused")
:
: Set pt = ws.PivotTables(1)
: pt.Delete ' error
: Set pt = Nothing
:
: Thanks
: Habib
:
:
:
:




All times are GMT +1. The time now is 02:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com