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:
Much thanks,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
Nick
Last edited by Nickster64; 12-12-2008 at 10:38 AM.
I solved it (actually I just searched Google for a while and found the solution!).
I needed to replace
With..ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount").Orientation = _ xlDataField
I hope this helps anyone else having the same problem!With ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount") .Orientation = xlDataField .Name = "Sum of Amount" .Function = xlSum End With
Best,
Nick
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks