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:

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
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
 

davie1982

Board Regular
Joined
Nov 19, 2007
Messages
170
Office Version
  1. 365
  2. 2019
yeah that's great! thanks.

Just 1 thing.. need the grand total only to stay in column F :P
 

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,368
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,767
Members
413,933
Latest member
Msar5586

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
Top