Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pivot Table Problem


I am using the following code to create a pivot table which I want to return
the sum function for "Balance". For some reason, the pivot table started
returning Count of Balance rather than Sum of Balance so I added the line
..PivotFields("Count of Balance").Function=xlSum. This changed the count to
sum. Now the pivot table is once again returning Sum of Balance initially
and the code hangs when it trys to convert the count to sum. Is there some
code I can use to cause the function to default to sum each time the pivot
table runs?

Range(FirstCell, LastCell).Select
CurrentRegion = Selection

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion.Address)

'Balance by AssignedTo
Set PT = PTCache.CreatePivotTable _
(TableDestination:="'AssignedTo'!R3C1", _
TableName:="PivotTable1")
With PT
.PivotFields("AssignedTo").Orientation = xlRowField
.PivotFields("Balance").Orientation = xlDataField
.PivotFields("Count of Balance").Function = xlSum
End With


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

You could change your code slightly:

'===========================
With PT.PivotFields("Balance")
.Orientation = xlDataField
.Caption = "Balance "
.Function = xlSum
End With
'============================

Boyd L. Colglazier wrote:
I am using the following code to create a pivot table which I want to return
the sum function for "Balance". For some reason, the pivot table started
returning Count of Balance rather than Sum of Balance so I added the line
.PivotFields("Count of Balance").Function=xlSum. This changed the count to
sum. Now the pivot table is once again returning Sum of Balance initially
and the code hangs when it trys to convert the count to sum. Is there some
code I can use to cause the function to default to sum each time the pivot
table runs?

Range(FirstCell, LastCell).Select
CurrentRegion = Selection

Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion.Address)

'Balance by AssignedTo
Set PT = PTCache.CreatePivotTable _
(TableDestination:="'AssignedTo'!R3C1", _
TableName:="PivotTable1")
With PT
.PivotFields("AssignedTo").Orientation = xlRowField
.PivotFields("Balance").Orientation = xlDataField
.PivotFields("Count of Balance").Function = xlSum
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
Problem inserting calculated pivot fields into Pivot Table (2007) wamiller36 Excel Discussion (Misc queries) 1 March 5th 10 11:40 PM
Pivot Table Problem DCO Excel Worksheet Functions 1 November 18th 09 08:59 PM
Pivot Table in Excel 2007 : Problem with % in Table spudsnruf Excel Discussion (Misc queries) 2 January 9th 08 09:53 PM
Pivot table problem Tendresse Excel Discussion (Misc queries) 1 August 17th 07 03:02 AM
Pivot Table problem jules Excel Discussion (Misc queries) 0 December 28th 04 07:45 PM


All times are GMT +1. The time now is 04:26 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"