PivotTable grouping issue vs memory/resource issue

Mr_Ragweed

Board Regular
Joined
Dec 10, 2012
Messages
74
So I am once again perplexed. From my data i create a pivot table. From that pivot table i "show report filter pages". On each of those pages i copy 2 of the columns and place them adjoining the new PT's. One is a % number and one is in currency. I then select the PT and the 2 new columns and create yet another PT. When i copy the formulas down using a final row statement (so the new columns are the same length as the PT) i cannot using the "grouping" function on the new PT. When i copy the formulas down through the whole column i CAN group the new PT but run out of memory/available resources when trying to complete the rest of the macro. Confused by that description? Codes are below: (By the way using Excel 2010, & i'm cutting and pasting from the main macro so i probably have chopped off some Dim's and if's. Bothe codes work but both result in baggage downstrem in the macro.

'This bit here copies my formula into the whole column but kills my resources
[code 1]
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'Copy GM% column over and convert to a number
FinalRow = ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row
For Each ws In Worksheets
ws.Activate

If Range("A1").Value = "Product Name" Then
ActiveSheet.Range("E4").Select
ActiveCell.FormulaR1C1 = "=Sum(RC[-2])*100"

Selection.AutoFill Destination:=Range("E4:E" & FinalRow), Type:=xlFillCopy

Range("E3").Select
ActiveCell.FormulaR1C1 = "GM%"
Range("G3").Select
ActiveCell.FormulaR1C1 = "AgVance Level"

Columns("E:E").Select
Selection.NumberFormat = "0.0"
Application.CutCopyMode = False
ActiveSheet.Range("F4").Select
ActiveCell.FormulaR1C1 = "=RC[-2]"

Selection.AutoFill Destination:=Range("F4:F" & FinalRow), Type:=xlFillCopy

Range("F3").Select
ActiveCell.FormulaR1C1 = "GM$"
Range("F4:F" & FinalRow).Select
Selection.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
Application.CutCopyMode = False

Range("G3").Select
Selection.AutoFilter
[end of code 1]

'this bit here copies the formula only to where i need it, but then i cannot group the resulting PT
[code 2 starts here]
For Each ws In Worksheets
ws.Activate

FinalRow = ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row
FinalCol = ActiveSheet.Cells(1, Application.Columns.Count).End(xlToLeft).Column
Set PRange = ActiveSheet.Cells(3, 1).Resize(FinalRow, 6)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)
If Range("A1").Value = "Product Name" Then
ActiveSheet.Range("E4").Select
Range("E4").FormulaR1C1 = "=Sum(RC[-2])*100"
Range("E4").Select
If ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row = 4 Then
Application.CutCopyMode = False
ElseIf ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row > 4 Then
Selection.AutoFill Destination:=Range("E4:E" & FinalRow), Type:=xlFillCopy
End If
Range("E4" & FinalRow).Select
Range("E3").Select
ActiveCell.FormulaR1C1 = "GM%"
Range("G3").Select
ActiveCell.FormulaR1C1 = "AgVance Level"
Range("G4").Select
Range("E4:E" & FinalRow).Select
Selection.NumberFormat = "0.0"
Application.CutCopyMode = False
End If
Next ws
'Copy GM$ column over and convert to a number
For Each ws In Worksheets
ws.Activate

FinalRow = ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row
If Range("A1").Value = "Product Name" Then
ActiveSheet.Range("F4").Select
ActiveCell.FormulaR1C1 = "=RC[-2]"
Range("F4").Select
If ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row = 4 Then
Application.CutCopyMode = False
ElseIf ActiveSheet.Cells(Application.Rows.Count, 1).End(xlUp).Row > 4 Then
Selection.AutoFill Destination:=Range("F4:F" & FinalRow), Type:=xlFillCopy
End If
Range("F4" & FinalRow).Select
Range("F3").Select
ActiveCell.FormulaR1C1 = "GM$"
Range("F4:F" & FinalRow).Select
Selection.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
Application.CutCopyMode = False
Range("G3").Select
Selection.AutoFilter
[code 2 ends here]

i had to do a count as i was getting an erro on pt's with only 1 row of data. Pt's are set up in Outline Form w/ compact row, hence starting in row 4. I this case "show report filter pages" yields about 540 new pt's. That number will never be the same and could probably be as high as maybe 2000ish. That's why i use a "For each" loop to find only the sheets i want as they have a unique cell as an identifier. The workbooks have other sheets and i don't know how to make a dynamic array of only "some" of the worksheets in a workbook.

If there's a better way i'm all ears....
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,216,073
Messages
6,128,646
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top