Sum a dynamic range with VBA sum which should be present even after VBA execution

krshnn

New Member
Joined
Mar 23, 2022
Messages
17
Office Version
  1. 2013
Platform
  1. Windows
Range("B2").formula = "=sum(b4:b300)".
The issue being here is b300 could be b400 or b100.
I want basically a sum formula which would stay even after VBA execution.
When I use worksheet function sum, it correctly computes but once the VBA is executed, only value is shown with formula gone.

So in nutshell, I want to sum a dynamic range. After summing the dynamic range and completion of VBA execution, sum formula should be present.

Disclaimer : I don't want to define name for the sum range and sum it. Naming sum range VBA method is not preferred
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Will that do?

VBA Code:
Sub SumColumn_B()

    Dim FinalRow_B As Long
    Dim WS As Worksheet
    
    Set WS = ActiveSheet
    FinalRow_B = WS.Cells(Rows.Count, 2).End(xlUp).Row + 1
    Range("B2").Formula = "=SUM(B4:B" & FinalRow_B - 1 & ")"

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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