Hi,
I recorded a macro that create a pivot table that gives me the following:
VB Code:
Sub Macro2() ' ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _ "BHD20060423!C1:C20").CreatePivotTable TableDestination:="", TableName:= _ "PivotTable2", DefaultVersion:=xlPivotTableVersion10 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) ActiveSheet.Cells(3, 1).Select ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array("Class", _ "SEA/BAS", "Data"), ColumnFields:="FY&P" With ActiveSheet.PivotTables("PivotTable2").PivotFields("OnOrder (Current)") .Orientation = xlDataField .Caption = "Sum of OnOrder (Current)" .Position = 1 .Function = xlSum End With With ActiveSheet.PivotTables("PivotTable2").PivotFields("OnOrder (Units)") .Orientation = xlDataField .Caption = "Sum of OnOrder (Units)" .Function = xlSum End With End Sub
It worked the time I recorded it, but not anymore.
I'm having an AddField method of PivotTable class failed error at the line
VB Code:
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array("Class", _ "SEA/BAS", "Data"), ColumnFields:="FY&P"
I don't know what the field "Data" is doing there, I didn't add it in the Wizard.
If there is a better way here is what I want to do.
Each week a workbook is created with ONE sheet in it, the sheet name change each week.
Data(Header) is starting at A1 and finish a T??? but always column T
In the Wizard I enter in the layout section for Row the field Class and the field SEA/BAS. For the Column I entering the field FY&P
In the data section I'm entering the Sum of OnOrder (Current) and Sum of OnOrder (Units)
The Pivot table has to be on a new sheet.
Really Need help here
Thanks




Reply With Quote