Hello, I recorded a macro to create and setup a pivottable from Sheet "Tags" to Sheet "Flt Hours". When I ran the recorded macro, I got a message saying Error 9: subscript out of range. The highlighted code is:
The last line " , DefaultVersion:=xlPivotTableVersion14 " is where it says the error is occurring. Here is the rest of the code:
I am using Windows 7, Excel 2010. The code works to put in the fields for the PivotTable, but fails when the table is being created. I'm familiar with VBA, but frankly, I'm stumped. I've looked at several different posts, and nothing I've seen matches this problem.
ActiveWorkbook.Worksheets("Flt Hrs").PivotTables("PivotTable1").PivotCache. _
CreatePivotTable TableDestination:="Flt Hrs!R3C6", TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion14
CreatePivotTable TableDestination:="Flt Hrs!R3C6", TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion14
The last line " , DefaultVersion:=xlPivotTableVersion14 " is where it says the error is occurring. Here is the rest of the code:
Sheets("Tags").Select
Range("A2").Select
ActiveWorkbook.Worksheets("Flt Hrs").PivotTables("PivotTable1").PivotCache. _
CreatePivotTable TableDestination:="Flt Hrs!R3C6", TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion14
Sheets("Flt Hrs").Select
Cells(3, 6).Select
ActiveWorkbook.ShowPivotTableFieldList = True
'Sheets("Flt Hours").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Primary Fault")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Partner")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Downtime Category")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Interval Hours"), "Sum of Interval Hours", xlSum
Range("A2").Select
ActiveWorkbook.Worksheets("Flt Hrs").PivotTables("PivotTable1").PivotCache. _
CreatePivotTable TableDestination:="Flt Hrs!R3C6", TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion14
Sheets("Flt Hrs").Select
Cells(3, 6).Select
ActiveWorkbook.ShowPivotTableFieldList = True
'Sheets("Flt Hours").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Primary Fault")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Partner")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Downtime Category")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Interval Hours"), "Sum of Interval Hours", xlSum
I am using Windows 7, Excel 2010. The code works to put in the fields for the PivotTable, but fails when the table is being created. I'm familiar with VBA, but frankly, I'm stumped. I've looked at several different posts, and nothing I've seen matches this problem.