I am running a macro that creates a pivot table and it seems to work ok if I can choose the cells to run the pivot table on. It is not possible to set up a default as the report changes in rows but not in columns. When I record using all cells, I get an error of 'runtime error 1004'
Unable to get the pivot table property of the pivot table class.
Seems to me that it almost needs to pause to let the pivot function catch up with the rest of macro.
Here is the code inside the debugger
Sub pivot6()
'
' pivot6 Macro
' Macro recorded 12/21/2007 by Christopher E Wantuch
'
'
Cells.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!C1:C13").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Posting Date")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Total Direct Hours"), "Count of Total Direct Hours" _
, xlCount
Range("B12").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of Total Direct Hours").Function = xlSum
End Sub
Any help would be greatly appreciated.
Bookmarks