I try to create a Pivot table with 3 elements inside the Pivot filter field.
These usually are in the same column, when I create the Pivots manually, but with VBA they are in the same row and I cannot understand why.
The Pivot I want to create has the following fields:
- Filters: Ship Date, Account name, Zip
- Rows: SAP Code
- Values: US Qty Shipped
Visually this is the result I obtain with my actual code:
And this is what I want to obtain (I made it manually without VBA, then I recorded the Macro following the same steps but I obtain the filters are always in the same column):
I tried also to select the "Compact Layout" from PivotTable tools without success.
Sub Shipped_qty_US()
Sheets("Tracker").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Tracker!R1C1:R72606C25", Version:=6).CreatePivotTable TableDestination:= _
"Foglio7!R3C1", TableName:="Tabella pivot1", DefaultVersion:=6
Sheets("Foglio7").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("Tabella pivot1")
.ColumnGrand = True
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = True
.SaveData = True
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = False
.CompactRowIndent = 1
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = False
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.FieldListSortAscending = False
.ShowValuesRow = False
.CalculatedMembersInFilters = False
.RowAxisLayout xlCompactRow
End With
With ActiveSheet.PivotTables("Tabella pivot1").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("Tabella pivot1").RepeatAllLabels xlRepeatLabels
Sheets("Foglio7").Select
Sheets("Foglio7").Name = "Shipped Qty US"
Sheets("Shipped Qty US").Select
Sheets("Shipped Qty US").Name = "PV Shipped Qty"
With ActiveSheet.PivotTables("Tabella pivot1").PivotFields("Ship Date")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("Tabella pivot1").PivotFields("Account Name")
.Orientation = xlPageField
.Position = 2
End With
With ActiveSheet.PivotTables("Tabella pivot1").PivotFields("Zip")
.Orientation = xlPageField
.Position = 3
End With
With ActiveSheet.PivotTables("Tabella pivot1").PivotFields("SAP Code")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("Tabella pivot1").AddDataField ActiveSheet.PivotTables( _
"Tabella pivot1").PivotFields("Qty Shipped"), "Somma di Qty Shipped", xlSum
Range("B5").Select
ActiveSheet.PivotTables("Tabella pivot1").DataPivotField.PivotItems( _
"Somma di Qty Shipped").Caption = "US Qty Shipped"
End Sub
Thank you very much for the help!