+ Reply to Thread
Results 1 to 3 of 3

Pivot tables - Sum instead of Count

  1. #1
    hiunnati
    Guest

    Pivot tables - Sum instead of Count


    Hi,

    What is the exact code which will give me Sum instead of Count for a
    Pivot Field?

    I have used following code but it gave me error

    Sheets("Summary").PivotTables("PivotTable1").PivotFields("Duration").Orientation
    = xlDataField

    Sheets("Summary").PivotTables("PivotTable1").PivotFields("Duration").Function
    = xlSum

    I got the following error

    Run-time error '1004'

    Unable to set the Function property of the PivotField class


    Can you help me?

    Regards


    --
    hiunnati

  2. #2
    Debra Dalgleish
    Guest

    Re: Pivot tables - Sum instead of Count

    You could use code similar to this:

    '==========================
    Sub PivotTest()
    Dim pt As PivotTable
    Dim pf As PivotField

    Set pt = Sheets("Summary").PivotTables("PivotTable1")
    Set pf = pt.PivotFields("Duration")

    With pf
    .Orientation = xlDataField
    .Function = xlSum
    End With
    End Sub
    '===================

    hiunnati wrote:
    > Hi,
    >
    > What is the exact code which will give me Sum instead of Count for a
    > Pivot Field?
    >
    > I have used following code but it gave me error
    >
    > Sheets("Summary").PivotTables("PivotTable1").PivotFields("Duration").Orientation
    > = xlDataField
    >
    > Sheets("Summary").PivotTables("PivotTable1").PivotFields("Duration").Function
    > = xlSum
    >
    > I got the following error
    >
    > Run-time error '1004'
    >
    > Unable to set the Function property of the PivotField class
    >
    >
    > Can you help me?
    >
    > Regards
    >
    >



    --
    Debra Dalgleish
    Contextures
    http://www.contextures.com/tiptech.html


  3. #3
    hiunnati
    Guest

    Re: Pivot tables - Sum instead of Count


    Thanks!!!
    It works

    Debra Dalgleish Wrote:
    > You could use code similar to this:
    >
    > '==========================
    > Sub PivotTest()
    > Dim pt As PivotTable
    > Dim pf As PivotField
    >
    > Set pt = Sheets("Summary").PivotTables("PivotTable1")
    > Set pf = pt.PivotFields("Duration")
    >
    > With pf
    > .Orientation = xlDataField
    > .Function = xlSum
    > End With
    > End Sub
    > '===================
    >
    > hiunnati wrote:
    > Hi,
    >
    > What is the exact code which will give me Sum instead of Count for a
    > Pivot Field?
    >
    > I have used following code but it gave me error
    >
    >
    > Sheets("Summary").PivotTables("PivotTable1").PivotFields("Duration").Orientation
    > = xlDataField
    >
    >
    > Sheets("Summary").PivotTables("PivotTable1").PivotFields("Duration").Function
    > = xlSum
    >
    > I got the following error
    >
    > Run-time error '1004'
    >
    > Unable to set the Function property of the PivotField class
    >
    >
    > Can you help me?
    >
    > Regards
    >
    >
    >
    >
    > --
    > Debra Dalgleish
    > Contextures
    > http://www.contextures.com/tiptech.html



    --
    hiunnati

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1