Hello,
I have a recorded a macro for a report,
I need to customize the recorded macro
please find the below
Sub DQAdjustments()
'
' DQAdjustments Macro
'
'
Sheets("DATA").Select
Cells.Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"DATA!R1C1:R1048576C29", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="Sheet3!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion12
Sheets("Sheet3").Select
Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PG")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"HPS_Shpt Adjustments KUSD")
.Orientation = xlRowField
.Position = 4
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"HPS_Sellout Adjustments KUSD")
.Orientation = xlRowField
.Position = 5
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("HPS_Shpt Adjustments KUSD"), _
"Count of HPS_Shpt Adjustments KUSD", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("HPS_Sellout Adjustments KUSD"), _
"Count of HPS_Sellout Adjustments KUSD", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of HPS_Shpt Adjustments KUSD")
.Caption = "Sum of HPS_Shpt Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of HPS_Sellout Adjustments KUSD")
.Caption = "Sum of HPS_Sellout Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PG")
.PivotItems("BCS").Visible = False
.PivotItems("#N/A").Visible = False
.PivotItems("(blank)").Visible = False
End With
Range("G34").Select
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "TS"
Range("B40").Select
Sheets("DATA").Select
Sheets.Add
ActiveWorkbook.Worksheets("TS").PivotTables("PivotTable1").PivotCache. _
CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Quarter")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PG")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"BCS_Shpt Adjustments KUSD")
.Orientation = xlRowField
.Position = 4
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"BCS_Sellout Adjustments KUSD")
.Orientation = xlRowField
.Position = 5
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Quarter")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("BCS_Shpt Adjustments KUSD"), _
"Count of BCS_Shpt Adjustments KUSD", xlCount
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("BCS_Sellout Adjustments KUSD"), _
"Count of BCS_Sellout Adjustments KUSD", xlCount
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Count of BCS_Shpt Adjustments KUSD")
.Caption = "Sum of BCS_Shpt Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Count of BCS_Sellout Adjustments KUSD")
.Caption = "Sum of BCS_Sellout Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PG")
.PivotItems("TS Care Pack (ESSN, IPG Comm)").Visible = False
.PivotItems("#N/A").Visible = False
.PivotItems("(blank)").Visible = False
End With
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "BCS"
Range("C29").Select
ActiveWindow.SmallScroll Down:=-21
End Sub
I have a recorded a macro for a report,
I need to customize the recorded macro
please find the below
Sub DQAdjustments()
'
' DQAdjustments Macro
'
'
Sheets("DATA").Select
Cells.Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"DATA!R1C1:R1048576C29", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="Sheet3!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion12
Sheets("Sheet3").Select
Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PG")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"HPS_Shpt Adjustments KUSD")
.Orientation = xlRowField
.Position = 4
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"HPS_Sellout Adjustments KUSD")
.Orientation = xlRowField
.Position = 5
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("HPS_Shpt Adjustments KUSD"), _
"Count of HPS_Shpt Adjustments KUSD", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("HPS_Sellout Adjustments KUSD"), _
"Count of HPS_Sellout Adjustments KUSD", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of HPS_Shpt Adjustments KUSD")
.Caption = "Sum of HPS_Shpt Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of HPS_Sellout Adjustments KUSD")
.Caption = "Sum of HPS_Sellout Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Quarter").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PG")
.PivotItems("BCS").Visible = False
.PivotItems("#N/A").Visible = False
.PivotItems("(blank)").Visible = False
End With
Range("G34").Select
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "TS"
Range("B40").Select
Sheets("DATA").Select
Sheets.Add
ActiveWorkbook.Worksheets("TS").PivotTables("PivotTable1").PivotCache. _
CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Quarter")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PG")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"BCS_Shpt Adjustments KUSD")
.Orientation = xlRowField
.Position = 4
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"BCS_Sellout Adjustments KUSD")
.Orientation = xlRowField
.Position = 5
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Quarter")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("BCS_Shpt Adjustments KUSD"), _
"Count of BCS_Shpt Adjustments KUSD", xlCount
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("BCS_Sellout Adjustments KUSD"), _
"Count of BCS_Sellout Adjustments KUSD", xlCount
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Count of BCS_Shpt Adjustments KUSD")
.Caption = "Sum of BCS_Shpt Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Count of BCS_Sellout Adjustments KUSD")
.Caption = "Sum of BCS_Sellout Adjustments KUSD"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("SO2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PG")
.PivotItems("TS Care Pack (ESSN, IPG Comm)").Visible = False
.PivotItems("#N/A").Visible = False
.PivotItems("(blank)").Visible = False
End With
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "BCS"
Range("C29").Select
ActiveWindow.SmallScroll Down:=-21
End Sub