Hi,
I am building the pivot table in macro in excel 2003. The table is big, it did not work in excel 2000 so I moved to 2003 and I can build it manually and record the macro for it. However in the program (vba) it does not work. I included displayalerts statement to pass a few warnings (message :do you want to replace contents of worksheet ) and it is running through but no data at all on the pivot tables. I am getting just blank pivot table.
Here is what is going on: It build pivot table and I can see it while it's running. It builds with the data correctly but it put pivot table on the top of the original table. And that's it.
After it's saved and closed when I open xls file I do not see data - not on new worksheet not on the original worksheet - so looks like it builds pivot table correctly but does not save it in the destination pivot table. I see only empty pivot data with no data at all even without field names.
The code is below just in case you need it, the saving of xls file is performed later in the main procedure.
I appreciate any help on this.
Sub do_pivot(filename)
'
'
Application.DisplayAlerts = False
Workbooks(filename).Sheets("R").Select
Cells.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"R!R1C1:R2657C19").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array( _
"S", "Sa", "ON1", _
"Customer Name(STo)", "VN", "PO", "PID", _
"Prt", "Q", "LS", "D"), PageFields:= _
"OMB"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("LR")
.Orientation = xlDataField
.Caption = "Sum of LR"
.Function = xlSum
End With
Application.DisplayAlerts = True
End Sub
Bookmarks