I need help with this code to create a new pivot table on a new shit, but there is an error on the part with the first 4 lines of the code , it is a recorded macro and i am really new to VBA code and code overall, i dont know what is really the problem
Sub Macro8()
'
' Macro8 Macro
'
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Sheet8").PivotTables("PivotTable2").PivotCache. _
CreatePivotTable TableDestination:="Pivot!R1C1", TableName:="PivotTable12" _
, DefaultVersion:=7
Sheets("Pivot").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("PivotTable12")
.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("PivotTable12").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("PivotTable12").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable12").PivotFields("Employee ID")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable12").PivotFields("Códigos")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable12").AddDataField ActiveSheet.PivotTables( _
"PivotTable12").PivotFields("Claimable Amount"), "Sum of Claimable Amount", _
xlSum
ActiveSheet.PivotTables("PivotTable12").PivotFields("Códigos").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable12").PivotFields("Códigos").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable12").PivotFields("Employee ID").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable12").PivotFields("Employee ID").LayoutForm _
= xlTabular
ActiveSheet.PivotTables("PivotTable12").PivotFields("Employee ID"). _
RepeatLabels = True
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub
To have the new pivot table inserted in a new worksheet with the specifics i need to be able to work with it
CodePudding user response:
I think you should check out the post below. There is already an answer there.
CodePudding user response:
That's a lot of code for what you described. Can you hit F8 several times and get to the line of code that throws the error? If you can't figure it out, see the sample code in the links below.
https://powerspreadsheets.com/vba-create-pivot-table/#2-Create-Pivot-Table-in-New-Sheet