automate pivot table with macro


Posted by Tonya on January 30, 2002 11:03 AM

Is it possible to incorporate the creation of a pivot table
with a macro.

Posted by Juan Pablo G. on January 30, 2002 11:20 AM

Yes.

Posted by Tonya on January 30, 2002 11:50 AM

How? I was able to create the macro, but when I attempted to run the macro it
gave an error and wanted to debug. I'll give it another try.



Posted by Juan Pablo G. on January 30, 2002 12:56 PM

Start with

Sub CreatePT()
Dim PT As PivotTable

Set PT = ActiveSheet.PivotTableWizard(SourceType:=xlDatabase, SourceData:=Range("A1:D200"))
With PT
.PivotFields("Year").Orientation = xlRowField
.PivotFields("Sales").Orientation = xlColumnField
End With

End Sub

Look at the Online Help. It does help, altough it can be a little confusing creating a Pivot Table through macro.

Juan Pablo G.