Subtotal Any Column

The_Rock

Board Regular
Joined
Jul 2, 2007
Messages
174
Hi Folks
I was wondering if there was a way of making a formula dynamic/generic so that it would subtotal any column I want.

The limitations would be that Row 1 always contains the header and that the result (subtotal) should be offset by 2 rows in the same column. So basically, if I have data in (for example) F2:F10, I could click on any cell in Column F and the subtotal would be in F12

This is a formula I use where I am telling it what Columns/Rows to look at.
Code:
 Range("X65536").End(xlUp).Offset(2, 0).FormulaR1C1 = "=SUBTOTAL(9,(R2C24:R[-2]C))"

The fields marked with ??? is what I would like to be the active column.
Code:
 Range("???65536").End(xlUp).Offset(2, 0).FormulaR1C1 = "=SUBTOTAL(9,(R2C???:R[-2]C))"
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I've found the following on-line, which I have changed to 'Subtotal' instead of sum but I still need to specify which column I want the total in, in the formula. Maybe this could help with some of your suggestions??

Code:
Sub Get_Rng_Address()
    Dim rAddress As Range, strAddress As String
    Dim SFormula As String
    Set rAddress = Application.InputBox("Select Range", Type:=8)
    strAddress = rAddress.Address
    Range("B65536").End(xlUp).Offset(2, 0).Value = "=SUBTOTAL(9," & strAddress & ")"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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