sum by range

sufin

New Member
Joined
Apr 19, 2023
Messages
6
Office Version
  1. 2021
  2. 2013
Platform
  1. Windows
1683105302443.png


here it is i want to if b5=closing then c5= "sum(c2:c4)-(e2:e4)"
correspontantly through all row eg: b8=closing c8=" sum(c2:c7)-(e2:e7)"
but should not be updated on previous (c5)
i created a macro with cell reference but when i add a row in the middle of this its not updating

VBA Code:
Private Sub worksheet_change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Value = "closing" Then Target.Offset(1, 0).Value = "opening"
Range("h2").Copy
If Target.Value = "closing" Then Target.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
If Target.Value = "closing" Then Target.Offset(1, 1).PasteSpecial Paste:=xlPasteValues
End Sub

additional information H2=sum(d2:d10000)-sum(e2:e10000)
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
how large is this worksheet?
If you are going to have large amounts of data, then I suggest not recording the data and processing it in the same sheet, or area of sheet.
The data should be one thing, and the report another.

dashboard_webinar.xlsx
ABCDEFGH
1
2
3DataReport
4DateTransactionAmountDateOpeningAmountClosing
52023-03-01original20002023-03-0120002000
62023-03-04tea-502023-03-042000-1501850
72023-03-04fuel-1002023-03-051850-501800
82023-03-05tea-50
9
Sheet4
Cell Formulas
RangeFormula
G5:G7G5=SUMIF($A$5:$A6,E5,$C$5:C6)
H5:H7H5=N(H4)+G5
F6:F7F6=H5
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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