amend simple code sum dynamic values without repeatedly

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i need adjusting my code i would sum only one time when run code not repeatedly every time it sum the values as in my code
VBA Code:
Sub sum_dynamic()
ir = Cells(Rows.Count, 1).End(xlUp).Row
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
ActiveCell.Offset(0, 0).Value = "total"
ActiveCell.Offset(0, 1).Select

ActiveCell.Formula = "=sum(b2:b" & ir & ")"

End Sub
thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about
VBA Code:
Sub sum_dynamic()
With Cells(Rows.Count, 1).End(xlUp)
   If .Value = "total" Then Exit Sub
   .Offset(1).Value = "total"
   .Offset(1, 1).FormulaR1C1 = "=sum(r2c2:r[-1]c2)"
End With
End Sub
 
Upvote 0
if the values in col d i try adjust but i failed
.Offset(1, 4).FormulaR1C1 = "=sum(r4c4:r[-1]c4)"
 
Upvote 0
It should be r2c4 for the 1st part not r4c4, assuming you want to sum from D2
 
Upvote 0
i amended your code to this :
VBA Code:
Sub sum_dynamic1()
With Cells(Rows.Count, 1).End(xlUp)
   If .Value = "total" Then Exit Sub
   .Offset(1).Value = "total"
   .Offset(1, 3).FormulaR1C1 = "=sum(r2c4:r[-1]c4)"
End With
End Sub
it successes i took advantage from your code thanks for your adjusting
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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