SebastianHuang
New Member
- Joined
- Dec 5, 2019
- Messages
- 38
- Office Version
- 2013
- Platform
- Windows
So I am asked to run Trial Balances, and do a pivot table with the columns and row, and amounts in value. I do this repetitively. Is there a way to macro it? Every time, I do a macro for pivot tables I run into errors.
VBA Code:
Sub Pivot_Table()
'
' Pivot_Table Macro
'
'
Range("D8").Select
Application.Run "PERSONAL.XLSB!TB_Macro"
Application.Run "PERSONAL.XLSB!HideColumns"
Range("A1").Select
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.Worksheets("Sheet2").PivotTables("PivotTable4").PivotCache. _
CreatePivotTable TableDestination:="Sheet1!R3C1", TableName:="PivotTable1" _
, DefaultVersion:=6
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1")
.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("PivotTable1").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PostingPeriod")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("TransDesc")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("AMOUNT DR/(CR)"), "Sum of AMOUNT DR/(CR)", xlSum
Columns("B:B").Select
Range("B11").Activate
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Style = "Comma"
Range("F6").Select
End Sub