# Rests in vba, and accumulation.

#### isaiasenzo

##### New Member
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>

### Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Replies
2
Views
176
Replies
2
Views
96
Replies
5
Views
93
Replies
2
Views
105
Replies
0
Views
36

1,109,435
Messages
5,528,746
Members
409,833
Latest member
tdnhan

### This Week's Hot Topics

• Change military grades into rank
Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
• VBA COUNTIF SOLUTION
Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
• INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...