How to keep a running 5 cell total

PlumGr8

Board Regular
Joined
Nov 23, 2017
Messages
136
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.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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.
You can do that, but it would likely have to be done with some VBA.
 
Upvote 0
You can do that, but it would likely have to be done with some VBA.
Maybe something like this, in the sheet module for your main sheet:

Edited to add a line to update B13 with the new B12 value as well.

The most recent value is entered into B10 and the values move up the sheet. This can be rearranged if you want the most recent value entered into B6 and move down.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B12")) Is Nothing Then
    Range("B6").Value = Range("B7").Value
    Range("B7").Value = Range("B8").Value
    Range("B8").Value = Range("B9").Value
    Range("B9").Value = Range("B10").Value
    Range("B10").Value = Range("B12").Value
    Range("B13").Value = Range("B13").Value + Range("B12").Value
End If
End Sub
 
Last edited:
Upvote 0
Ok, so trying to tweak it. For B13 all i usually have it =B11+B12. And if/when i want to add more truck, like if i want to to the same setup but in the C column, can i add it below the B section? Obviously not the greatest wth VBA, i can tweak things as i get going ok, just usually need help with the inital setup on this stuff. Thanks a lot, working as needed so far, just need to tweak those couple things.
 
Upvote 0
I tried tweaking it, for the inital change, think this looks good, am i correct?

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B12")) Is Nothing Then
Range("B6").Value = Range("B7").Value
Range("B7").Value = Range("B8").Value
Range("B8").Value = Range("B9").Value
Range("B9").Value = Range("B10").Value
Range("B10").Value = Range("B12").Value

End If
End Sub
 
Upvote 0
Ok, so trying to tweak it. For B13 all i usually have it =B11+B12. And if/when i want to add more truck, like if i want to to the same setup but in the C column, can i add it below the B section? Obviously not the greatest wth VBA, i can tweak things as i get going ok, just usually need help with the inital setup on this stuff. Thanks a lot, working as needed so far, just need to tweak those couple things.

I tried tweaking it, for the inital change, think this looks good, am i correct?

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B12")) Is Nothing Then
Range("B6").Value = Range("B7").Value
Range("B7").Value = Range("B8").Value
Range("B8").Value = Range("B9").Value
Range("B9").Value = Range("B10").Value
Range("B10").Value = Range("B12").Value

End If
End Sub
You don't want B13 to be a running total? Just the B11 + the current hours entered into B12?

And you want to add another column that does the same stuff?
 
Upvote 0
It is a running total, but as things change with trucks, engines etc we have to change the previous and total. Typically when we update the total we enter B13 's total in B11's, and the hours for the days in B12's to give the new total. I've been trying it, i "think" that change i did is working as needed, just not sure how to expand it to other columns as needed.
 
Upvote 0
Try this, you can expand it for as many columns as you want to add by adjusting the Range("B12:E12") to whatever column you need in the following line:

ie: For 5 trucks, the range would be B12:F12, etc.
VBA Code:
If Not Intersect(Target, Range("B12:E12")) Is Nothing And Target.Count <= 1 Then

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B12:E12")) Is Nothing And Target.Count <= 1 Then
    Cells(6, Target.Column).Value = Cells(7, Target.Column).Value
    Cells(7, Target.Column).Value = Cells(8, Target.Column).Value
    Cells(8, Target.Column).Value = Cells(9, Target.Column).Value
    Cells(9, Target.Column).Value = Cells(10, Target.Column).Value
    Cells(10, Target.Column).Value = Cells(12, Target.Column).Value
End If
End Sub
 
Upvote 0
Awesome that one works
Try this, you can expand it for as many columns as you want to add by adjusting the Range("B12:E12") to whatever column you need in the following line:

ie: For 5 trucks, the range would be B12:F12, etc.
VBA Code:
If Not Intersect(Target, Range("B12:E12")) Is Nothing And Target.Count <= 1 Then

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B12:E12")) Is Nothing And Target.Count <= 1 Then
    Cells(6, Target.Column).Value = Cells(7, Target.Column).Value
    Cells(7, Target.Column).Value = Cells(8, Target.Column).Value
    Cells(8, Target.Column).Value = Cells(9, Target.Column).Value
    Cells(9, Target.Column).Value = Cells(10, Target.Column).Value
    Cells(10, Target.Column).Value = Cells(12, Target.Column).Value
End If
End Sub
i should be able to adjust from there. Now one last thing, as i try to organize the mess of these workbooks. They have another book that is similar, but instead of columns specific, its by rows.

So the normal entry would be B11, B12, B13. Then the next truck may be B15, B16, B17. We have no data past column M i think, so would i be easier to move the target from B12 to say M6, M7, etc. Then the next vehicl be N6, N7, etc?
 
Upvote 0
Awesome that one works

i should be able to adjust from there. Now one last thing, as i try to organize the mess of these workbooks. They have another book that is similar, but instead of columns specific, its by rows.

So the normal entry would be B11, B12, B13. Then the next truck may be B15, B16, B17. We have no data past column M i think, so would i be easier to move the target from B12 to say M6, M7, etc. Then the next vehicl be N6, N7, etc?
Okay, so this is what you have for the first book:

Book1
ABCDE
5Truck 1Truck 2Truck 3Truck 4
655
713
81013
9522
10215175
111000150020005055
12Current Hours215175
13Total1002151520175060
Sheet5
Cell Formulas
RangeFormula
B13:E13B13=B11+B12


Does this look like what you have for the second?

Book1
B
10Truck 1
111000
1215
131015
14Truck 2
15950
1610
17960
18Truck 3
191125
205
211130
Sheet6
Cell Formulas
RangeFormula
B13,B21,B17B13=B11+B12


I am not quite sure what you mean by changing the target to M6, M7 etc. Is that where you would update the current hours then? If my example above matches, then with code, the target would be something like B12,B16,B20.

The target in the code is which cell you are updating with the current hours, so whatever cells those are, that would be the target range.
 
Upvote 0

Forum statistics

Threads
1,215,098
Messages
6,123,082
Members
449,094
Latest member
mystic19

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