Pivot Table Error

G

Guest

I used the Macro Recorder to create the following code to generate a Pivot
Table. When I try to run it I get the following error: "AddFeilds method of
Pivot Table Class Failed".

Any ideas how to make this work?

Sheets("Allocation").Select
Cells.Select
Application.CutCopyMode = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Allocation!C1:C6").CreatePivotTable TableDestination:= _
"'[Conversion Workbook.xls]Allocation'!R1C8",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("PivotTable1").AddFields
RowFields:=Array("Social Security Number", "Source Name"),
ColumnFields:="Fund Name"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Cash").Orientation = _
xlDataField
Range("H4").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Social Security
Number"). _
Subtotals = Array(False, False, False, False, False, False, False,
False, False, False, _
False, False)
Range("J5").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of
Cash").Function = _
xlSum
End Sub
 
D

Debra Dalgleish

The SourceData is "Allocation!C1:C6" which doesn't look right for a
pivot table source.
If you change that to the correct range, perhaps the macro will run
correctly.
I used the Macro Recorder to create the following code to generate a Pivot
Table. When I try to run it I get the following error: "AddFeilds method of
Pivot Table Class Failed".

Any ideas how to make this work?

Sheets("Allocation").Select
Cells.Select
Application.CutCopyMode = False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Allocation!C1:C6").CreatePivotTable TableDestination:= _
"'[Conversion Workbook.xls]Allocation'!R1C8",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTables("PivotTable1").AddFields
RowFields:=Array("Social Security Number", "Source Name"),
ColumnFields:="Fund Name"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Cash").Orientation = _
xlDataField
Range("H4").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Social Security
Number"). _
Subtotals = Array(False, False, False, False, False, False, False,
False, False, False, _
False, False)
Range("J5").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of
Cash").Function = _
xlSum
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top