Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
I have open/high/low/close price data for thirty stocks, and each stock has its own worksheet. I wanted to write a macro that would create a pivottable on sheet 1 using the price data on sheet 1, then automatically move to worksheet 2, create a pivottable on sheet 2 using the price data on sheet 2, and so on until all thirty worksheets had their own pivottable. With help from this site (thanks Tom Ogilvy), I recorded a macro which worked perfectly. For some reason, I made a minor change to the section of code which creates the pivottable, and it no longer works. I have tried unsuccessfully to fix the problem, but to no avail. The macro code appears below: Sub Macro1() ' ' Macro1 Macro ' Macro recorded 9/16/2004 by Renee/Eric ' ' Keyboard Shortcut: Ctrl+h ' Dim ws As Worksheet For Each ws In Worksheets (Array("Sheet29", "Sheet28", "Sheet27", _ "Sheet26", "Sheet25", "Sheet24", "Sheet23", "Sheet22", "Sheet21", "Sheet20", _ "Sheet19", "Sheet18", "Sheet17", "Sheet16", "Sheet15", "Sheet14", "Sheet13", _ "Sheet12", "Sheet11", "Sheet10", "Sheet9", "Sheet8", "Sheet7", "Sheet6", "Sheet5", _ "Sheet4", "Sheet3", "Sheet2", "Sheet1")) ws.Activate Rows("1:4").Select Selection.Delete Shift:=xlUp Range("C:D,F:F").Select Range("F1").Activate Selection.Delete Shift:=xlToLeft Range("D1").Select ActiveCell.FormulaR1C1 = "% Chg" Columns("D:D").Select Selection.NumberFormat = "0.00%" Range("D2").Select ActiveCell.FormulaR1C1 = "=(RC[-1]-RC[-2])/RC[-2]" Range("D2").Select Selection.AutoFill Destination:=Range("D2:D170"), Type:=xlFillDefault Range("D2:D170").Select Range("A1").CurrentRegion.Select The error is somewhere in these 5 lines of code: ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _ ActiveSheet.Name & "!r1c1:r170c4").CreatePivotTable TableDestination:= _ "'[DJIA Components.xls]" & ActiveSheet.Name & "'!R2C6", TableName:="PivotTable1", _ DefaultVersion:=xlPivotTableVersion10 With ActiveSheet.PivotTables("PivotTable1").PivotFields ("DATE") .Orientation = xlRowField .Position = 1 End With ActiveSheet.PivotTables("PivotTable1").AddDataFiel d ActiveSheet.PivotTables( _ "PivotTable1").PivotFields("% Chg"), "Sum of % Chg", xlSum Range("F2").Select With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sum of % Chg") .Function = xlAverage .NumberFormat = "0.00%" End With Range("F4").Select Selection.Group Start:=True, End:=True, Periods:=Array(False, False, False, _ False, True, False, False) Next End Sub Can anyone see what I may have altered so as to make macro unusable? I wish I could remember! Thanks in advance for any insight- Eric Bentrovato |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Multiple PivotTables | Excel Discussion (Misc queries) | |||
Multiple PivotTables on one spreadsheet | Excel Discussion (Misc queries) | |||
[pivottables] multiple table selection fields update in one click... | Excel Discussion (Misc queries) | |||
Create a summary list without using PivotTables? | Excel Worksheet Functions | |||
Macro to synch three pivottables based on same data | Excel Programming |