I tried 10000 times to make a pivot table from macro and always fail ,, please help me
that's the code
that's the code
Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R6C1:R2000C36", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet4!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
Sheets("Sheet4").Select
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Sr."), "Sum of Sr.", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("ID Number")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Name")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Occupation")
.Orientation = xlRowField
.Position = 3
End With
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub
Last edited by a moderator: