I've written a macro that is making a pivot table from data I have in my worksheet. I keep getting this error:
Run-time error '1004'
Unable to get the PivotFields property of the PivotTable class.
Here is my code:
Range("B17:J35").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R17C2:R35C10").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable16"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable16").SmallGrid = False
Application.Run "BLPLinkReset"
With ActiveSheet.PivotTables("PivotTable16").PivotFields("Sector")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable16").PivotFields("Percent Assets")
.Orientation = xlDataField
.Position = 1
End With
Application.CommandBars("PivotTable").Visible = False
Run-time error '1004'
Unable to get the PivotFields property of the PivotTable class.
Here is my code:
Range("B17:J35").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R17C2:R35C10").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable16"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable16").SmallGrid = False
Application.Run "BLPLinkReset"
With ActiveSheet.PivotTables("PivotTable16").PivotFields("Sector")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable16").PivotFields("Percent Assets")
.Orientation = xlDataField
.Position = 1
End With
Application.CommandBars("PivotTable").Visible = False