Rests in vba, and accumulation.

isaiasenzo

New Member
Joined
Feb 26, 2019
Messages
1
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>


 

Some videos you may like

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.

Watch MrExcel Video

Forum statistics

Threads
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...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top