Macro Error

  • Thread starter Thread starter acss
  • Start date Start date
A

acss

I create a pivot table monthly for two data sheets in a workbook. I want to
have the steps of creating the pivots automated so i am using a macro but i
receive a run-time error "9" Subscript out of Range. Could it be that in the
macro creating process , i included the naming of the pivot sheets?
 
The code for the macro is:
Sub Macro1()
Range("A1:C4").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R4C3").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("description")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("amount"), "Sum of amount", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("code")
.Orientation = xlColumnField
.Position = 1
End With
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "flowers"
Range("C24").Select
End Sub
 
Back
Top