So what's wrong this code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Employee Roster- Active Employe!R1C1:R2547C5", Version:= _
xlPivotTableVersion12).CreatePivotTable TableDestination:= _
"Employee Roster- Active Employe!R1C7", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion12
Sheets("Employee Roster- Active Employe").Select
Cells(1, 7).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Employee_Number"), "Count of Employee_Number", _
xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Cost_Center_(Division)")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Department")
.Orientation = xlColumnField
.Position = 1
End With
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub
It gives me:
"run-time error '5'"
"Invalid procedure call or argument"
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Employee Roster- Active Employe!R1C1:R2547C5", Version:= _
xlPivotTableVersion12).CreatePivotTable TableDestination:= _
"Employee Roster- Active Employe!R1C7", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion12
Sheets("Employee Roster- Active Employe").Select
Cells(1, 7).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Employee_Number"), "Count of Employee_Number", _
xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Cost_Center_(Division)")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Department")
.Orientation = xlColumnField
.Position = 1
End With
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub
It gives me:
"run-time error '5'"
"Invalid procedure call or argument"