Report

Need to calculate monthly avg and yearly miles from odometer [Solved/Closed]

Ask a question jamishore 10Posts Wednesday August 23, 2017Registration date September 13, 2017 Last seen - Last answered on Sep 13, 2017 at 09:41 PM by vcoolio
Good afternoon,

I am having an issue figuring out how to get excel to calculate the yearly mileage and monthly avg by just monthly odometer readings.

I Here is my worksheet:
https://www.dropbox.com/s/gs5dzetcrfeauvn/Average%20Miles.xlsx?dl=0

I am pulling a complete blank on how to do this and any assistance is greatly appreciated! :)
Helpful
+0
plus moins
Hello Jamishore,

You would like to total each row in Column N and average the month to date values in Column O?

If so, in cell N2, type in:

=SUM(
(the parenthesis just may appear automatically).

From B2, drag across to M2. You will see a formula begin to develop in the formula bar. Place a closing parenthesis at the end of the formula and then click away. Being a table that you are using, the formula should flash fill downwards and the totals will appear in Column N for each row.

In cell O2, type in:

=average(

Again, from B2 drag across to M2. You will again see a formula begin to develop. Close the parenthesis and click away. The formula should again flash fill for you. The values will change as you fill in the currently empty cells.

I hope that this helps.

Cheerio,
vcoolio.
Helpful
+0
plus moins
Thank you very much for getting back to me.

Since there is an odometer reading listed in those columns, it wouldn't come up with the actual yearly mileage if I did a Sum formula. it would add them all up correct?

Instead I ended up having to add additional columns to calculate the mileage for each month and manually come up with the Yearly Miles by subtracting the starting odometer reading in January from this months odometer reading for column CB (which I will have to do each month).

And because there will always be a negative amount in the current month I am unable to average those columns, so instead I divided column CB by 12 to get the monthly average for column CC.

Any advise would be greatly appreciated.

Also, here is my updated spreadsheet:
https://www.dropbox.com/s/19k44tbw16gk6cx/Average%20Miles.xlsx?dl=0
Helpful
+0
plus moins
Hello Jami,

It may be a better option (but its up to you) to use two separate tables side by side. One table is for the monthly odometer readings and the other can be used to do the calculations without the negative values. We can then use VBA to insert formulae for the calculations.Have a look at the following sample I knocked up for you:-

http://ge.tt/2r7NeWm2

To start with, type a value into Column H (1st August), larger than the previous value, then click away (or press enter or down arrow) and you'll see the second table update, including the yearly total and average to date. Do the same for the remaining months then start a second row if you wish. Totals and averages should update.

As you can see, I haven't actually set the sample up as tables but you can do this yourself just to see that it all still works as it should. Remember to keep at least one column between the tables as per the sample.

Following is the code for this:-

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim c As Range
    Dim lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row

If Intersect(Target, Range("A2:M" & lr)) Is Nothing Then Exit Sub

Application.ScreenUpdating = False

Range("O2:Z" & lr).Formula = "=IF(B2-A2=0,"""",B2-A2)"
Range("AA2:AA" & lr).Formula = "=SUM(O2:Z2)"
Range("AB2:AB" & lr).Formula = "=AVERAGE(O2:Z2)"

For Each c In Range("O2:Z" & lr)
      If Left(c.Value, 1) = "-" Then
          c.ClearContents
      End If
Next c

Sheet1.Columns.AutoFit
Application.ScreenUpdating = True

End Sub


It is a Worksheet_Change event and needs to be placed into the sheet1 (or your master sheet) module.

Let us know your thoughts.

Cheerio,
vcoolio.
Helpful
+0
plus moins
That worked great! Thank you soooo much.
Helpful
+0
plus moins
Hi Jami,

You're welcome. I'm glad that I was able to help.

Cheerio,
vcoolio.

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!