#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Pivot Table

I am trying to remove all data from a pivot table. The following code
does not work every time. I don't understand why.

Set PT = Worksheets("PT").PivotTables("PT1")

With PT
'clear old items
On Error Resume Next
.PivotFields("Data").Orientation = xlHidden
.RowFields(1).Orientation = xlHidden

'add row field
.AddFields RowFields:="LocationID"
'add the data filed
With .PivotFields("Amount")
.Orientation = xlDataField
.Function = xlSum
End With

End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Pivot Table

More Information:

The program works when there are two items in the "Data" area of the
pivot table, when there is only one, it doesn't work.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Pivot Table

If you're using Excel 2002 or later version, you can use the following:

'==================
Dim pf As PivotField

With PT
'clear old items
'On Error Resume Next
For Each pf In PT.DataFields
pf.Orientation = xlHidden
Next pf
.RowFields(1).Orientation = xlHidden

'add row field
.AddFields RowFields:="LocationID"
'add the data filed
With .PivotFields("Amount")
.Orientation = xlDataField
.Function = xlSum
End With

End With
'============================

C. Roenbaugh wrote:
I am trying to remove all data from a pivot table. The following code
does not work every time. I don't understand why.

Set PT = Worksheets("PT").PivotTables("PT1")

With PT
'clear old items
On Error Resume Next
.PivotFields("Data").Orientation = xlHidden
.RowFields(1).Orientation = xlHidden

'add row field
.AddFields RowFields:="LocationID"
'add the data filed
With .PivotFields("Amount")
.Orientation = xlDataField
.Function = xlSum
End With

End With



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
Pivot Table and Pivot Table dates are not in correct order ls Charts and Charting in Excel 3 July 14th 09 04:02 PM
Copying values from pivot table to cells outside pivot table richzip Excel Discussion (Misc queries) 4 January 16th 08 11:03 PM
Filter lines with Pivot table and non pivot table columns Grover Charts and Charting in Excel 4 September 28th 07 03:16 AM
Help required with setting up a pivot table with the source on sheet1 to have the pivot table created on sheet called "report" Diana[_5_] Excel Programming 0 August 21st 03 10:19 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"