+ Reply to Thread
Results 1 to 2 of 2

Thread: Pivot table code to always have 'Sum of' in the Layout Data Field?

  1. #1
    Registered User
    Join Date
    11-06-2008
    Location
    Illinois
    Posts
    63

    Question Pivot table code to always have 'Sum of' in the Layout Data Field?

    A macro I am running that creates a pivot table sometimes randomly chooses between the 'Sum of' or 'Count of' option within the Data Field of my pivot table Layout. I need this always be 'Sum of'.

    This is the code I use now:
    Sub VoucherReport()
        Selection.AutoFilter
        Selection.AutoFilter Field:=10, Criteria1:="Submitted"
        ActiveWindow.SmallScroll ToRight:=2
        Selection.AutoFilter Field:=18, Criteria1:="=08*", Operator:=xlAnd
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.Copy
        Sheets.Add
        ActiveSheet.Paste
        Range("H:H,K:K").Select
        Range("K1").Activate
        Application.CutCopyMode = False
        Selection.NumberFormat = "mm/dd/yy;@"
        Sheets("Sheet1").Select
        Sheets("Sheet1").Name = "ElecSysSubmitted"
        Range("A1").Select
        ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
            "ElecSysSubmitted!R1C1:R86C19").CreatePivotTable TableDestination:="", _
            TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
        ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
        ActiveSheet.Cells(3, 1).Select
        ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:= _
            "Engagement Owner", PageFields:="Vendor Name"
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount").Orientation = _
            xlDataField
        Columns("B:B").Select
        Selection.NumberFormat = "#,##0"
        Sheets("Sheet2").Select
        Sheets("Sheet2").Name = "SummarySubmitted"
        ActiveWorkbook.Save
        Application.DisplayAlerts = False
        
    End Sub
    Much thanks,

    Nick
    Last edited by Nickster64; 12-12-2008 at 10:38 AM.

  2. #2
    Registered User
    Join Date
    11-06-2008
    Location
    Illinois
    Posts
    63

    Wink

    I solved it (actually I just searched Google for a while and found the solution!).

    I needed to replace
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount").Orientation = _
            xlDataField
    With..

        
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount")
       .Orientation = xlDataField
       .Name = "Sum of Amount"
       .Function = xlSum
    End With
    I hope this helps anyone else having the same problem!

    Best,

    Nick

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0