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"]
<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]
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]
[/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]