Subtotal - put results in next column

davie1982

Board Regular
Joined
Nov 19, 2007
Messages
170
Office Version
  1. 365
  2. 2019
Hiya, i know i may be on a 'i need help' spree but i hope this is the last one for today =P

i got this code here for subtotals:

Code:
    Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(6), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True

what i want to be able to do is... instead of the results displaying in array 6 (column F) i want them to display in column G while still summing up column F. Is this at all possible? Column G is blank with a title, but it's where the subtotals are meant to show. At the moment when the subtotals is done, i have to stop the macro so that the user cuts and pastes the subtotals from F to G.

Thanks
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Davie.

Maybe like this? HTH, Fazza

Code:
Sub Macro1()
  With Selection
    .Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(7), _
              Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    .Columns("G:G").SpecialCells(xlCellTypeFormulas).Replace _
        What:="G", Replacement:="F", LookAt:=xlPart
  End With
End Sub
 
Upvote 0
yeah that's great! thanks.

Just 1 thing.. need the grand total only to stay in column F :P
 
Upvote 0
Like this, Davie? Regards, Fazza

Code:
Sub Macro1()
 
  With Selection
    .Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(7), _
              Replace:=True, PageBreaks:=False, SummaryBelowData:=True
    .Columns("G:G").SpecialCells(xlCellTypeFormulas).Replace _
        What:="G", Replacement:="F", LookAt:=xlPart
  End With
 
  With Cells(Cells.Rows.Count, "G").End(xlUp)
    .Clear
    .Offset(, -1).FormulaR1C1 = "=SUBTOTAL(9, R1C:R[-1]C)"
  End With
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

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