Hello,
I have recorded three macros which create a pivot table one after the other on the sheet "Results". For some reason, sometimes it works and other times it crashes. I think it has something to do with the pivot table name - but I changed these. Here's my code:
Sub CreateGrid()
Application.CommandBars("PivotTable"
.Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Data!R1C1:R116C13"
.CreatePivotTable TableDestination:= _
"[Inter.xls]Results!R2C1", TableName:="DateTable"
', DefaultVersion:= _
'xlPivotTableVersion10
ActiveSheet.PivotTables("DateTable"
.AddFields RowFields:="Party", _
ColumnFields:="Type"
ActiveSheet.PivotTables("DateTable"
.PivotFields("Type"
.Orientation = _
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable"
.Visible = False
End Sub
Sub CreateMth()
Application.CommandBars("PivotTable"
.Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Month"
.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Month!R1C1:R116C13"
.CreatePivotTable TableDestination:= _
"[Inter.xls]Results!R35C1", TableName:="MonthTable", DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables("MonthTable"
.AddFields RowFields:="Party", _
ColumnFields:="Type"
ActiveSheet.PivotTables("MonthTable"
.PivotFields("Type"
.Orientation = _
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable"
.Visible = False
End Sub
Sub CreateWk()
Application.CommandBars("PivotTable"
.Visible = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Week"
.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Week!R1C1:R116C13"
.CreatePivotTable TableDestination:= _
"[Inter.xls]Results!R75C1", TableName:="WeekTable", DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables("WeekTable"
.AddFields RowFields:="Party", _
ColumnFields:="Type"
ActiveSheet.PivotTables("WeekTable"
.PivotFields("Type"
.Orientation = _
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable"
.Visible = False
End Sub
I have recorded three macros which create a pivot table one after the other on the sheet "Results". For some reason, sometimes it works and other times it crashes. I think it has something to do with the pivot table name - but I changed these. Here's my code:
Sub CreateGrid()
Application.CommandBars("PivotTable"
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Data!R1C1:R116C13"
"[Inter.xls]Results!R2C1", TableName:="DateTable"
', DefaultVersion:= _
'xlPivotTableVersion10
ActiveSheet.PivotTables("DateTable"
ColumnFields:="Type"
ActiveSheet.PivotTables("DateTable"
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable"
End Sub
Sub CreateMth()
Application.CommandBars("PivotTable"
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Month"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Month!R1C1:R116C13"
"[Inter.xls]Results!R35C1", TableName:="MonthTable", DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables("MonthTable"
ColumnFields:="Type"
ActiveSheet.PivotTables("MonthTable"
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable"
End Sub
Sub CreateWk()
Application.CommandBars("PivotTable"
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Week"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Week!R1C1:R116C13"
"[Inter.xls]Results!R75C1", TableName:="WeekTable", DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables("WeekTable"
ColumnFields:="Type"
ActiveSheet.PivotTables("WeekTable"
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable"
End Sub