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

Hi,

Im recording a pivot table macro, with the aim of playing this macro for a
set of data in a given format.

My prooblem when recording is that when I am at Layout Data,
and I drag the second field (TC) into Data,
sometimes it turns up as Sum Of TC
and sometimes as Count of TC

How do I ensure that its always Sum Of TC

Thanks

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

Hi,
At creation, you could do:

With ActiveSheet.PivotTables("PivotTable1")
'.....
'Bellow , adds 2 fields to the pivot, and then move one to Data as a
Sum
.AddFields RowFields:="Field1", ColumnFields:="TC"
With .PivotFields("TC")
.Orientation = xlDataField
.Caption = "Sum of TC"
.Function = xlSum '<-------------
End With
End With

or

Dim pf as Pivotfield
On error resume next
Set pf= ActiveSheet.PivotTables("PivotTable2").PivotFields ("Count of TC")
If err=0 then 'case where the field is found; change to Sum
pf.Function =xlSum
End if
On error goto 0

Regards,
Sebastien

"teresa" wrote:

Hi,

Im recording a pivot table macro, with the aim of playing this macro for a
set of data in a given format.

My prooblem when recording is that when I am at Layout Data,
and I drag the second field (TC) into Data,
sometimes it turns up as Sum Of TC
and sometimes as Count of TC

How do I ensure that its always Sum Of TC

Thanks

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

Thanks so much for this

"sebastienm" wrote:

Hi,
At creation, you could do:

With ActiveSheet.PivotTables("PivotTable1")
'.....
'Bellow , adds 2 fields to the pivot, and then move one to Data as a
Sum
.AddFields RowFields:="Field1", ColumnFields:="TC"
With .PivotFields("TC")
.Orientation = xlDataField
.Caption = "Sum of TC"
.Function = xlSum '<-------------
End With
End With

or

Dim pf as Pivotfield
On error resume next
Set pf= ActiveSheet.PivotTables("PivotTable2").PivotFields ("Count of TC")
If err=0 then 'case where the field is found; change to Sum
pf.Function =xlSum
End if
On error goto 0

Regards,
Sebastien

"teresa" wrote:

Hi,

Im recording a pivot table macro, with the aim of playing this macro for a
set of data in a given format.

My prooblem when recording is that when I am at Layout Data,
and I drag the second field (TC) into Data,
sometimes it turns up as Sum Of TC
and sometimes as Count of TC

How do I ensure that its always Sum Of TC

Thanks

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
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
Filter lines with Pivot table and non Pivot table columns Grover Excel Discussion (Misc queries) 1 September 26th 07 12:48 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:48 PM.

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

About Us

"It's about Microsoft Excel"