Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Steps from Macro recorder for Pivot table will not run as a Macro

I am using Excel 97.

Background: I have a spreadsheet that, as part of a set of actions, I
create a pivot table on. Due to this being a repetitive task by
multiple users I would like to write VBA code to create the pivot
table. This code would then be distributed as part of an addin for
this set of actions (the rest of the actions and the addin have
already been created - this would be an addition).

Method:
I turned on Macro recorder, created the pivot table (1 column field, 3
row fields, a sum data field), performed grouping on the column field,
eliminated subtotals on the rows, eliminated grand totals on the
columns then turned off the macro recorder. The pivot table on the
screen was correct. The macro recorded code is below.

Sub PivotMacro()
'
Range("B3:T350").Select
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:=
_
"Jan2004min!R3C2:R350C20", TableDestination:="",
TableName:="PivotTable2"

ActiveSheet.PivotTables("PivotTable2").AddFields
RowFields:=Array("Line", _
"MvT", "Length"), ColumnFields:="Pstg date"
ActiveSheet.PivotTables("PivotTable2").PivotFields ("Pos
Val").Orientation = _
xlDataField

ActiveSheet.PivotTables("PivotTable2").PivotSelect "'Pstg
date'[All]", _
xlLabelOnly
Selection.Group Start:=True, End:=True, Periods:=Array(False,
False, False, _
False, True, False, False)

ActiveSheet.PivotTables("PivotTable2").PivotSelect "MvT", xlButton
ActiveSheet.PivotTables("PivotTable2").PivotFields ("MvT").Subtotals
= Array( _
False, False, False, False, False, False, False, False, False,
False, False, False)

ActiveSheet.PivotTables("PivotTable2").PivotSelect "Line",
xlButton
ActiveSheet.PivotTables("PivotTable2").PivotFields ("Line").Subtotals
= Array( _
False, False, False, False, False, False, False, False, False,
False, False, False)

ActiveSheet.PivotTables("PivotTable2").PivotSelect "",
xlDataAndLabel
ActiveSheet.PivotTables("PivotTable2").ColumnGrand = False

End Sub

Problem:
When I try to run this as a macro, it only goes so far then stops (no
error messages). It creates the rows and columns fields but does not
add the data field. If I divide it into six individual macros and run
each separately, they will all work but the code will not work if ran
as one macro (it seems it needs to be in the six individual parts).
The six macro "steps" a
1. Create pivot table, row and column fields
2. Create data field
3. Group data field
4. Eliminate subtotals on first row field
5. Eliminate subtotal on second row field
6. Eliminate subtotal on columns

Question:
Is there something I am missing that is a way around this so that it
can run in one macro? Or is it a function of Excel 97? (I recently
had another problem where for Excel 97 I had to divide the steps into
separate macros where for Excel 2002 it worked as one macro).

Thanks for any help,
Nancy
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
macro recorder and formulas Dave F Excel Discussion (Misc queries) 2 March 19th 07 02:43 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM
Macro recorder Fossil_Rock Excel Discussion (Misc queries) 1 July 30th 05 08:10 PM
Macro Recorder-Relative relation ChasX Excel Discussion (Misc queries) 3 June 28th 05 12:51 AM


All times are GMT +1. The time now is 04:27 PM.

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

About Us

"It's about Microsoft Excel"