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

Group,

I coded a pivot table into my macro and it works
sometimes; however, sometimes the data in the pivot table
works under the field settings as a count rather then a
sum. How do i make my macro change the data to a sum if it
is a count function and not give me an error . Thanks in
advance.Code for pivot down below

Regards,

Fish

'Macro

Dim fname As String
Dim PTcache As PivotCache
Dim PT As PivotTable

fname = ActiveWorkbook.Name



Range("a1").Select

'Application.DisplayAlerts = False

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

Set PT = PTcache.CreatePivotTable _
(Tabledestination:="", _
Tablename:="Pivottable1")

With PT
.PivotFields("LOCATION").Orientation = xlPageField
.PivotFields("CAT TYPES").Orientation = xlColumnField
.PivotFields("DATE").Orientation = xlRowField
.PivotFields("Cat Color").Orientation = xlRowField
.PivotFields("DATE").LayoutSubtotalLocation = xlAtTop
.PivotFields("DATE").LayoutForm = xlOutline
.PivotFields("COST OF CAT").Orientation = xlDataField

End With
ActiveSheet.PivotTables(PT).PivotFields("Count of
Cost of cat").Function = xlSum

ActiveSheet.PivotTables(PT).ShowPages
PageField:="Location"

End sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Pivot table sum data

Hi Fish

Try this:

For Each pvtfld In ActiveSheet.PivotTables(1).DataFields
pvtfld.Function = xlSum
Next

Doesn't make a difference if the datafield is sum or
count. If it is already sum then nothing happens. If the
field is count then it will be changed to sum.

Mike


-----Original Message-----
Group,

I coded a pivot table into my macro and it works
sometimes; however, sometimes the data in the pivot table
works under the field settings as a count rather then a
sum. How do i make my macro change the data to a sum if

it
is a count function and not give me an error . Thanks in
advance.Code for pivot down below

Regards,

Fish

'Macro

Dim fname As String
Dim PTcache As PivotCache
Dim PT As PivotTable

fname = ActiveWorkbook.Name



Range("a1").Select

'Application.DisplayAlerts = False

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

Set PT = PTcache.CreatePivotTable _
(Tabledestination:="", _
Tablename:="Pivottable1")

With PT
.PivotFields("LOCATION").Orientation = xlPageField
.PivotFields("CAT TYPES").Orientation = xlColumnField
.PivotFields("DATE").Orientation = xlRowField
.PivotFields("Cat Color").Orientation = xlRowField
.PivotFields("DATE").LayoutSubtotalLocation = xlAtTop
.PivotFields("DATE").LayoutForm = xlOutline
.PivotFields("COST OF CAT").Orientation = xlDataField

End With
ActiveSheet.PivotTables(PT).PivotFields("Count of
Cost of cat").Function = xlSum

ActiveSheet.PivotTables(PT).ShowPages
PageField:="Location"

End sub
.

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
View Pivot Table Source data as a Data Table InsomniacFolder Excel Discussion (Misc queries) 6 April 12th 10 05:17 PM
Lookup data in a variable table & retrieve data from a pivot table Shawna Excel Worksheet Functions 3 October 10th 08 11:11 PM
Filter lines containing pivot table and non pivot table data Grover Excel Worksheet Functions 0 September 24th 07 07:20 PM
Pivot Table - Use Other Pivot Table as Data Source WCM Excel Discussion (Misc queries) 1 January 25th 07 06:39 PM
How do I sort pivot table data outside a pivot table Michael Excel Worksheet Functions 1 January 4th 07 02:45 PM


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