Rests in vba, and accumulation.

isaiasenzo

New Member
Joined
Feb 26, 2019
Messages
4
Hi, how are you helping me with the following?
What I need is that in a cell eg B7.
This cell is automatically updated for me.
And I need that when the next value is lower than the previous one
accumulate in the cela for example C7.
If the value of cell B4 is greater than the previous one, they do not accumulate.


THIS IS MY CODE
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Dim anterior1 As Integer
Dim anterior2 As Integer


Private Sub Worksheet_Change(ByVal Target As Range)
Celda = "B7"


If Not Application.Intersect(Target, Range(Celda)) Is Nothing Then


Worksheets(1).Range("C7").Value = Worksheets(1).Range("B7").Value - anterior1
anterior1 = Worksheets(1).Range("B7").Value
Worksheets(1).Range("D7").Value = Worksheets(1).Range("C7").Value + anterior2
anterior2 = Worksheets(1).Range("C7").Value


End If
End Sub

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

B7 C7

<tbody>
</tbody>
198 0
180 -18
175 -23
180 -23

<tbody>
</tbody>


Capture.jpg
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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