Dynamic Range Subtotal Calculation

Jasvindra

New Member
Joined
Jul 31, 2018
Messages
38
Below is My COde

Sub Subtotal()
'
' Macro1 Macro
'
Dim rwMax As Integer
Dim MYRANGE As Range
rwMax = Cells(Rows.Count, 1).End(xlUp).Row
Range("B" & rwMax + 1).Select

ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,B2:B" & rwMax & ")"
End Sub

But I am getting =SUBTOTAL(9,'B2':'B16') in the result cell
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
It needs to be .Formula, not .FormulaR1C1
 
Upvote 0
Try this:

Code:
Sub Subtotal()'
' Macro1 Macro
'
Dim rwMax As Integer
Dim MYRANGE As Range
rwMax = Cells(rows.Count, 1).End(xlUp).row
Range("B" & rwMax + 1).Select


ActiveCell.Formula = "=SUBTOTAL(9,B2:B" & rwMax & ")"
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Hi Nardagus

I am using the below formula in one of my Macro. In which this subtotal cell is copied with respective value for which filter has been applied and pasted on next sheet.

But Macro has been giving same Total(Total without filter) value for each loop.
May be it is because I am using rwmax in formula which refers to last row in the data.
Could you please help me



ActiveCell.Formula = "=SUBTOTAL(9,B2:B" & rwMax & ")"
 
Upvote 0
Try
Code:
ActiveCell.Formula = "=SUBTOTAL([COLOR=#ff0000]109[/COLOR],B2:B" & rwMax & ")"
 
Upvote 0
Can you post the code that you are using.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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