Marcin
05-12-2011, 02:57 AM
Hi All
I'm having trouble with generating a pivot tablel through VBA. I recorded a macro and changed only the SourceData. The code crushes and does nothing. I tried to run the macro I recorded and to my suprise the code crushed as well, resulting with the same error (Invalid procedure argument). Could any one explain to me why is this code crushing. Below I place a sample code:
Set c = sheet.Range("A1", "G10")
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
c, Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="BCS Finance Data!R1C9", TableName:= _
"PivotTable3", DefaultVersion:=xlPivotTableVersion12
'Sheets("BCS Finance Data").Select
sheet.cells(1, 9).Select
sheet.Range("J9").Select
With sheet.PivotTables("PivotTable3")
.InGridDropZones = True
.RowAxisLayout xlTabularRow
End With
With sheet.PivotTables("PivotTable3").PivotFields("PLs")
.Orientation = xlRowField
.Position = 1
End With
I'm having trouble with generating a pivot tablel through VBA. I recorded a macro and changed only the SourceData. The code crushes and does nothing. I tried to run the macro I recorded and to my suprise the code crushed as well, resulting with the same error (Invalid procedure argument). Could any one explain to me why is this code crushing. Below I place a sample code:
Set c = sheet.Range("A1", "G10")
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
c, Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="BCS Finance Data!R1C9", TableName:= _
"PivotTable3", DefaultVersion:=xlPivotTableVersion12
'Sheets("BCS Finance Data").Select
sheet.cells(1, 9).Select
sheet.Range("J9").Select
With sheet.PivotTables("PivotTable3")
.InGridDropZones = True
.RowAxisLayout xlTabularRow
End With
With sheet.PivotTables("PivotTable3").PivotFields("PLs")
.Orientation = xlRowField
.Position = 1
End With