This is my code:
I placed the pivottable on the existing sheet because it wouldn't work when i try to put it on a new sheet.
Plus, i saved the macro in the personal folder, but it wouldn't work for other workbooks. Please note that the worksheet name is the same in the other wkbooks.
Sub Headcount()
'
' Headcount Macro
'
' Keyboard Shortcut: Ctrl+h
'
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"DynamicRange", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="'Employee Roster- Active Employe'!R1C25", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion12
Sheets("Employee Roster- Active Employe").Select
Cells(1, 25).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Employee_Number"), "Count of Employee_Number", _
xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Department")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Cost_Center_(Division)")
.Orientation = xlRowField
.Position = 1
End With
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub