Hi all,
I have a workbook that starts blank everytime time its opened, and at the push of a button launches a macro that imports some data, sorts and formats it. All good so far. I am able to create a pivot table (using the wizard) to analyse the data I am left with and display the desired results, but I would like to be able to automate this process, so that the table 'appears' when the original macro has done its work and sorted the data. I have tried (cheating?) recording a macro of the pivot table wizard, but it fails to run and I am not capable of fixing the programing.
Is there an easy way to automate the pivot table process or a macro that can be written that will work?
Here is the code generated by the record macro function
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!C6:C8").CreatePivotTable TableDestination:= _
"'[CRM data1]Sheet1'!R31C9", TableName:="PivotTable6", DefaultVersion:= _
xlPivotTableVersion10
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable6").PivotFields("Package")
.Orientation = xlPageField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable6").PivotFields("Location")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable6").AddDataField ActiveSheet.PivotTables( _
"PivotTable6").PivotFields("Stand_Size"), "Count of Stand_Size", xlCount
ActiveWorkbook.ShowPivotTableFieldList = False
Range("I31").Select
ActiveSheet.PivotTables("PivotTable6").PivotFields("Count of Stand_Size"). _
Function = xlSum
End Sub
It hangs up at the first 'with' statement, not sure why, but its a simple table, with only the 3 columns of data in it. Any help will be much appreciated,
Cheers,
EDIT: It pays to have a thorough check of all code eh? For whatever reason, when the macro was recorded, it give erroneous array for the source data - once I spotted this and changed it to the correct values, it all works.
Bookmarks