TkdKidSnake
Board Regular
- Joined
- Nov 27, 2012
- Messages
- 245
- Office Version
- 365
- Platform
- Windows
Hi all,
I am trying to insert a pivot table into my worksheet however the data can vary in length and I am not sure how to this using the pivot table function, the code I have currently is below.
If anyone can help me with this it would be greatly appreciated.
Thanks in advance
I am trying to insert a pivot table into my worksheet however the data can vary in length and I am not sure how to this using the pivot table function, the code I have currently is below.
Code:
Sub InsertPivotTable()'
' InsertPivotTable Macro
'
'
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"RawData!R1C1:R617C15", Version:=6).CreatePivotTable TableDestination:= _
"Sheet1!R3C1", TableName:="PivotTable5", DefaultVersion:=6
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable5")
.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("PivotTable5").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("PivotTable5").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Area")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
"PivotTable5").PivotFields("Days Past" & Chr(10) & "Due"), "Sum of Days Past" & Chr(10) & "Due", xlSum
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Sum of Days Past" & Chr(10) & "Due")
.Caption = "Average of Days Past"
.Function = xlAverage
.NumberFormat = "0.0"
End With
Range("A1").Select
End Sub
If anyone can help me with this it would be greatly appreciated.
Thanks in advance