When I run the following macro, it comes back with "unable to get the pivot fields property of the pivot table class". Any ideas? Debugger hi-lights:
Thanks
Rich (BB code):
Cells.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'1_HC_INFO'!C1:C16").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable5", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
"PivotTable5").PivotFields("Headcount"), "Count of Headcount", xlCount ActiveSheet.PivotTables("PivotTable5").PivotFields("Count of Headcount"). _
Function = xlSum
With ActiveSheet.PivotTables("PivotTable5").PivotFields("BusVal_1")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Bus_val 2")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Class")
.Orientation = xlRowField
.Position = 3
End With
Sheets("Sheet8").Select
Sheets("Sheet8").Name = "OnePager_Pivot"
Sheets("OnePager").Select
Cells.Replace What:="#REF!", Replacement:="OnePager_Pivot!$A$3", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, _
ReplaceFormat:=False
Cells.Replace What:="#REF!", Replacement:="OnePager_Pivot!", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, _
ReplaceFormat:=False
End Sub
Thanks