lakshmipathi123
Board Regular
- Joined
- Jul 10, 2012
- Messages
- 52
- Office Version
- 365
- Platform
- Windows
Hi Experts,
I have an error while creating an pivot. Please see below code and let me know error.
Sub Pivot()
'
' Macro1 Macro
'
Dim MyRange As Range
Sheets("Pivot - Recon").Select
Cells.Select
Selection.Delete Shift:=xlUp
Sheets("Main").Select
Range("A6").Select
Set MyRange = ActiveCell.CurrentRegion
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=MyRange, Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="'[UFAR Macro Ver 1.0.xlsm]Pivot - Recon'!R1C1", TableName:= _
"Pivot", DefaultVersion:=xlPivotTableVersion15
ActiveSheet.PivotTables("Pivot").AddDataField ActiveSheet.PivotTables( _
"Pivot Recon").PivotFields("Cost"), "Sum of Cost", xlSum
ActiveSheet.PivotTables("Pivot").AddDataField ActiveSheet.PivotTables( _
"Pivot Recon").PivotFields("Ltd Depr"), "Sum of Ltd Depr", xlSum
With ActiveSheet.PivotTables("Pivot").PivotFields("Category")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Pivot").PivotFields("Sub Category")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("Pivot").PivotFields("BU")
.Orientation = xlRowField
.Position = 3
End With
Columns("B:C").Select
Selection.NumberFormat = "#,##0.00_);(#,##0.00)"
Cells.Select
Columns.AutoFit
End Sub
Thank you,
Lakshmipathi
I have an error while creating an pivot. Please see below code and let me know error.
Sub Pivot()
'
' Macro1 Macro
'
Dim MyRange As Range
Sheets("Pivot - Recon").Select
Cells.Select
Selection.Delete Shift:=xlUp
Sheets("Main").Select
Range("A6").Select
Set MyRange = ActiveCell.CurrentRegion
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=MyRange, Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="'[UFAR Macro Ver 1.0.xlsm]Pivot - Recon'!R1C1", TableName:= _
"Pivot", DefaultVersion:=xlPivotTableVersion15
ActiveSheet.PivotTables("Pivot").AddDataField ActiveSheet.PivotTables( _
"Pivot Recon").PivotFields("Cost"), "Sum of Cost", xlSum
ActiveSheet.PivotTables("Pivot").AddDataField ActiveSheet.PivotTables( _
"Pivot Recon").PivotFields("Ltd Depr"), "Sum of Ltd Depr", xlSum
With ActiveSheet.PivotTables("Pivot").PivotFields("Category")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Pivot").PivotFields("Sub Category")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("Pivot").PivotFields("BU")
.Orientation = xlRowField
.Position = 3
End With
Columns("B:C").Select
Selection.NumberFormat = "#,##0.00_);(#,##0.00)"
Cells.Select
Columns.AutoFit
End Sub
Thank you,
Lakshmipathi