LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Recording a Macro to create a Pivot Table

I believe you need to delete the old PT first before creating a new one in
the same place. It may be easier to just create the PT once manually and use
it as a template for importing new data from CSVs to the same PT, and then
Refresh and SAVEAS.

Mike F
"Sandi B" <Sandi wrote in message
...
I am trying to create a macro which will open a CSV file - save it as a
spreadsheet and then create a pivot table. I have recorded a macro but I
continue to get a runtime error of "1004 - PivotTableWizard method of
Worksheet class failed" I have no idea what I'm doing wrong - any help
much
appreciated.
This is what the data is like

NDR Quarter
6400 2006Q3
6400 2006Q3
16422 2006Q3
14450 2006Q3
48000 2006Q3
6427 2006Q3
-19200 2006Q4
19200 2006Q4
32000 2006Q4
23750 2006Q4
34000 2006Q4

And here is the code
Private Sub Workbook_Open()
Dim Pt As PivotTable
'
' Macro6 Macro
'

'
Workbooks.Open Filename:="c:\q_ndr.csv"
ActiveWorkbook.SaveAs Filename:="C:\q_ndr1.xls", FileFormat:=xlNormal,
_
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"q_ndr!R1C1:R12C2").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable7", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
Range("A3").Select
ActiveSheet.PivotTables("PivotTable7").AddDataFiel d
ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("NDR"), "Sum of NDR", xlSum
With ActiveSheet.PivotTables("PivotTable7").PivotFields ("Quarter")
.Orientation = xlRowField
.Position = 1
End With
Range("A5").Select
End Sub



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a pivot table in a new worksheet by recording a macro razib Excel Worksheet Functions 1 January 26th 12 10:42 PM
Record Macro to Create Pivot Table Ken Excel Discussion (Misc queries) 1 April 25th 07 09:42 PM
Can I run a macro to create a pivot table? Eqa Excel Discussion (Misc queries) 2 April 8th 07 06:16 AM
macro to create a pivot table Catie79 Excel Programming 1 November 22nd 05 09:59 PM
Assign a macro to create a pivot table acsugguiyao Excel Programming 2 June 23rd 05 03:04 AM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"