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

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

[TABLE="width: 310"]
<tbody>[TR]
[TD="align: left"]
B7 C7

<tbody>
</tbody>
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]198 0
180 -18
175 -23[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]180 -23[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Capture.jpg
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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