I'm trying to run a pivot in Macro where the Pivot needs to choose the whole sheet and not a specific range as the data pasted in the sheet may fall in different range or rows however the columns are stable.,
Below given is the coding for that Macro Recording for Pivot.
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"NewHiVal!R1C1:R719C26", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Pivot!R3C1", TableName:="PivotTable3", DefaultVersion _
:=xlPivotTableVersion15
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Site")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Item Number")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Description")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Qty on Hand"), "Sum of Qty on Hand", xlSum
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Qty in transit"), "Sum of Qty in transit", xlSum
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Qty Non-Nettable"), "Sum of Qty Non-Nettable", _
xlSum
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Qty on Order"), "Sum of Qty on Order", xlSum
ActiveSheet.PivotTables("PivotTable3").PivotSelect "Description[All]", _
xlLabelOnly + xlFirstRow, True
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Description")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable3").PivotSelect "Description[All]", _
xlLabelOnly + xlFirstRow, True
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Description")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable3").PivotSelect "'Item Number'[All]", _
xlLabelOnly + xlFirstRow, True
ActiveSheet.PivotTables("PivotTable3").ShowValuesRow = True
ActiveSheet.PivotTables("PivotTable3").PivotFields("Item Number").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable3").PivotFields("Item Number").LayoutForm = _
xlTabular
Thanks in advance for the help.,
Bookmarks