Delete pivot table

H

HSalim[MVP]

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
 
T

Tom Ogilvy

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
 
H

HSalim[MVP]

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







: 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
:
:
:
: : > 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
: >
: >
:
:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top