How to keep a running 5 cell total

PlumGr8

Board Regular
Joined
Nov 23, 2017
Messages
145
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Wasn't sure the best way to word it. But i am tryign to find a way to create and "average" of our hours over the past 5 or 10 deliveries, but also auto updates. we have a prior hours, driven hours then total hours. Say B11, 12, 13. So B11 would show 1000 hrs, B12 would say 15 hours, B13 would show 1015 hours. Every day we update the hours in B12 for todays value. But is there a way to keep a running previous total? Like the last 5 days say B6 - B10 will keep the most recent enteries while deleteing the previous enteries? We do this on another sheet to get an averge time per truck, but trying to see if i can combine it all on to 1 page.
 
Code adjusted to ignore rows less than 12.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Row Mod 4 = 0 And Target.Column = 2 And Target.Row > 11 And Target.Count <= 1 Then
    Cells(9, (Target.Row / 4) + 10).Value = Cells(8, (Target.Row / 4) + 10).Value
    Cells(8, (Target.Row / 4) + 10).Value = Cells(7, (Target.Row / 4) + 10).Value
    Cells(7, (Target.Row / 4) + 10).Value = Cells(6, (Target.Row / 4) + 10).Value
    Cells(6, (Target.Row / 4) + 10).Value = Cells(5, (Target.Row / 4) + 10).Value
    Cells(5, (Target.Row / 4) + 10).Value = Cells(Target.Row, 2).Value
Else
    GoTo ReEnableEvents
End If
ReEnableEvents:
Application.EnableEvents = True
End Sub
I did just try that one as well that one is also good, as long as people keep the row formatting the same. But we also have a notes section after all this stuff, around row 100 or so. Unless there is a way to stop below a certain row?
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I did just try that one as well that one is also good, as long as people keep the row formatting the same. But we also have a notes section after all this stuff, around row 100 or so. Unless there is a way to stop below a certain row?
Absolutely, the code can be adjusted to account for any limits you would like to add.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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