Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

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.

Check out our Excel VBA Resources

Re: automate pivot table with macro

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


Re: automate pivot table with macro

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.


Re: automate pivot table with macro

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.


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.