Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PE PE is offline
external usenet poster
 
Posts: 14
Default Pivot Table Macro

I have recorded a macro (using relative references) which creats a pivot
table but when I run it I get a runtime error 5 and on clicking debug the
second line/paragraph is highlighted:

Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDa tabase, SourceData:= _
"Unpaid Invoices (2)!R2C1:R164C5", Version:=xlPivotTableVersion12).
_
CreatePivotTable TableDestination:="Sheet2!R3C1",
TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion12

I don't know what is causing the macro to breakdown immediately after
creating a new sheet.

Would appreciate your help.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Pivot Table Macro

Hi PE

Assume the data starts in B3 on the UNPAIDINVOICE sheet and you would like
to put the Pivot Table in E12 on the new sheet. Leave the table destination
and table names arguement blank to start. That should avoid the error you
are getting now You can fill them in later in the code. Select range B3 and
set SRange equal to the current region. Use DRange to position the pivot
table on the new sheet that the pivot wizard method adds.

Sub AddPivot()
Dim SRange As Range
Dim DRange As Range

Sheets("UnpaidInvoices").Select
Range("B3").Select
Set SRange = ActiveCell.CurrentRegion

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
SRange).CreatePivotTable TableDestination:="", TableName:= _
"", DefaultVersion:=xlPivotTableVersion12

Set DRange = Range("e12")

With ActiveSheet
.PivotTableWizard TableDestination:=DRange
.PivotTables(1).Name = "Unpaid Invoices"
.PivotTables(1).AddFields RowFields:="X", ColumnFields:="Y"
.PivotTables(1).PivotFields("Z").Orientation = xlDataField
End With

ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable").Visible = False

Set SRange = Nothing
Set DRange = Nothing
End Sub

Regards,
Mike

"PE" wrote:

I have recorded a macro (using relative references) which creats a pivot
table but when I run it I get a runtime error 5 and on clicking debug the
second line/paragraph is highlighted:

Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDa tabase, SourceData:= _
"Unpaid Invoices (2)!R2C1:R164C5", Version:=xlPivotTableVersion12).
_
CreatePivotTable TableDestination:="Sheet2!R3C1",
TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion12

I don't know what is causing the macro to breakdown immediately after
creating a new sheet.

Would appreciate your help.



Reply
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
Pivot table macro nickd via OfficeKB.com Excel Discussion (Misc queries) 3 July 15th 08 05:34 PM
pivot table macro skippy51 New Users to Excel 2 May 14th 08 01:06 PM
Pivot Table from Macro Dave Excel Discussion (Misc queries) 2 November 15th 07 05:00 PM
Macro and Pivot Table Prashanta Excel Programming 0 May 26th 04 12:40 PM
Steps from Macro recorder for Pivot table will not run as a Macro Nancy[_5_] Excel Programming 0 April 2nd 04 10:33 PM


All times are GMT +1. The time now is 01:21 PM.

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"