Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Collecting data for MPG (miles per gallon) calculation

I have a workbook that a user will log in various vehicle expenses.
One of the features is that it will calculate the MPG for each gas
purchase if the tank is filled up. This is simple, but I also want it
to calculate the MPG to including times when the user does NOT fill
the tank. This is done by adding the gallons used since the last fill
up thru the most recent fill up. It will divide that number by the
total miles driven during this period. The data is collected via a
userform, and the data is pasted to another sheet within the same
workbook. Here’s a example:

We’ll assume the headers Date Fillup ? Gal and OD Reading is in
cells A1-D1. The last line (the 2/15/10 entry) is in cells A5-D5.


Date Fillup ? Gal OD reading
1/1/2010 Y 14.25 24500
1/15/2010 N 15.25
2/1/2010 N 13.25
2/15/2010 Y 13.58 25500

Since a Y was entered on the last purchase, and it was N in the entry
prior, the calculation would be
(15.25+13.25+13.58) / (25500-24500) = 17.8 MPG from 1/15/10 thru the
2/15/10 fill up.

What I want to happen is when a Y is recognized on the current gas
purchase, it will:
1) do the simple calculation if the previous gas purchase was Y. That
was the case in the 1/1/10 entry.
2) It will calculate nothing if the User indicates N in the current
purchase.
3) If the user enters Y, and the previous entry was a N, then it will
add the gallons used since the last fill up, and divide that number by
the difference between the current OD reading, and the last reading
with a Y. This was the scenario in the example above that resulted in
the 17.8 MPG.

I hope I laid this out clear enough, and gave enough information. If
someone can help me with the coding to perform this task, I would
appreciate it.

As always, thanks for your help.

jeff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Collecting data for MPG (miles per gallon) calculation

Hi Jeff,

You van try something like this

I asume your details start at row 2

Add 3 columns
In these column the functione starts from row 3

1:
Titled: Summarized Galons
funcion: =IF(B2="Y",C3,C3+E2)

2:
Titled: Forwardded Reading
Function: =IF(B3="Y",D3,F2)

3:
Titles: MPG
Function: =IF(B3="Y",(F3-F2)/E3,"")

THurther more I think there is an error in your calculation.
I can not reproduce the result of 17.8 MPG

HTH,

Wouter
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Collecting data for MPG (miles per gallon) calculation

First off, you have your formula inverted the MPG calc should be
(25500-24500)/(15.25+13.25+13.58)= 23.8 MPG

The key to this calculation is finding and using the last fillup date

Date Fillup Gal OD Last Fillup Gal Miles MPG
1/1/2010 Y 14.25 24500
1/15/2010 N 15.25 1/1/2010
2/1/2010 N 13.25 1/1/2010
2/15/2010 Y 13.58 25500 1/1/2010 42.08 1000 23.8
3/1/2010 N 14.25 2/15/2010
3/15/2010 Y 14.25 26200 2/15/2010 28.5 700 24.6
4/1/2010 Y 13.58 26500 3/15/2010 13.58 300 22.1

For explanation I added four columns with formulas starting in row 3 (row 1
being the heading and row 2 the start point.

For the last fillup date in e2 =LOOKUP(2,1/($B$2:$B2="Y"),$A$2:$A2)

The Gal Used in
F2=IF(B3="Y",SUMPRODUCT(--($A$2:$A3$E3),--($A$2:$A3<=$A3),$C$2:$C3),"")

The miles driven in G2 =IF(B3="Y",$D3-VLOOKUP($E3,$A$2:$D3,4),"")

The MPG in H2=IF(F3<"",G3/F3,"")

This can be condensed into one monster formula
=IF(B3="Y",($D3-VLOOKUP($E3,$A$2:$D3,4))/SUMPRODUCT(--($A$2:$A3=$E3),--($A$2:$A3<$A3),$C$2:$C3),"")

The absolute and relative references are key to copying this down. That is
the $A$2:$A3 ties the formula to the start $A$2 and $A3 will expand the
formula range to match the row.
--
If this helps, please remember to click yes.


"jeff" wrote:

I have a workbook that a user will log in various vehicle expenses.
One of the features is that it will calculate the MPG for each gas
purchase if the tank is filled up. This is simple, but I also want it
to calculate the MPG to including times when the user does NOT fill
the tank. This is done by adding the gallons used since the last fill
up thru the most recent fill up. It will divide that number by the
total miles driven during this period. The data is collected via a
userform, and the data is pasted to another sheet within the same
workbook. Heres a example:

Well assume the headers Date Fillup ? Gal and OD Reading is in
cells A1-D1. The last line (the 2/15/10 entry) is in cells A5-D5.


Date Fillup ? Gal OD reading
1/1/2010 Y 14.25 24500
1/15/2010 N 15.25
2/1/2010 N 13.25
2/15/2010 Y 13.58 25500

Since a Y was entered on the last purchase, and it was N in the entry
prior, the calculation would be
(15.25+13.25+13.58) / (25500-24500) = 17.8 MPG from 1/15/10 thru the
2/15/10 fill up.

What I want to happen is when a Y is recognized on the current gas
purchase, it will:
1) do the simple calculation if the previous gas purchase was Y. That
was the case in the 1/1/10 entry.
2) It will calculate nothing if the User indicates N in the current
purchase.
3) If the user enters Y, and the previous entry was a N, then it will
add the gallons used since the last fill up, and divide that number by
the difference between the current OD reading, and the last reading
with a Y. This was the scenario in the example above that resulted in
the 17.8 MPG.

I hope I laid this out clear enough, and gave enough information. If
someone can help me with the coding to perform this task, I would
appreciate it.

As always, thanks for your help.

jeff
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default Collecting data for MPG (miles per gallon) calculation

On Apr 26, 11:35*am, jeff wrote:
I have a workbook that a user will log in various vehicle expenses.
One of the features is that it will calculate the MPG for each gas
purchase if the tank is filled up. This is simple, but I also want it
to calculate the MPG to including times when the user does NOT fill
the tank. This is done by adding the gallons used since the last fill
up thru the most recent fill up. It will divide that number by the
total miles driven during this period. The data is collected via a
userform, and the data is pasted to another sheet within the same
workbook. Here’s a example:

We’ll assume the headers Date *Fillup ? *Gal *and OD Reading is in
cells A1-D1. The last line (the 2/15/10 entry) is in cells A5-D5.

Date * *Fillup ? * * * *Gal * * OD reading
1/1/2010 * * * *Y * * * 14.25 * 24500
1/15/2010 * * * N * * * 15.25
2/1/2010 * * * *N * * * 13.25
2/15/2010 * * * Y * * * 13.58 * 25500

Since a Y was entered on the last purchase, and it was N in the entry
prior, the calculation would be
(15.25+13.25+13.58) / (25500-24500) = 17.8 MPG from 1/15/10 thru the
2/15/10 fill up.

What I want to happen is when a Y is recognized on the current gas
purchase, it will:
1) do the simple calculation if the previous gas purchase was Y. That
was the case in the 1/1/10 entry.
2) It will calculate nothing if the User indicates N in the current
purchase.
3) If the user enters Y, and the previous entry was a N, then it will
add the gallons used since the last fill up, and divide that number by
the difference between the current OD reading, and the last reading
with a *Y. This was the scenario in the example above that resulted in
the 17.8 MPG.

I hope I laid this out clear enough, and gave enough information. If
someone can help me with the coding to perform this task, I would
appreciate it.

As always, thanks for your help.

jeff


In the event that the user does not fill the tank, how do you
determine how many gallons were used since the last fill up?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Miles per gallon spreadsheet Greg[_5_] Excel Worksheet Functions 2 March 28th 09 07:04 PM
Averaging miles per gallon TckyTina Excel Worksheet Functions 3 April 29th 08 09:17 PM
Miles Calculation? Ewing25 Excel Programming 3 April 29th 08 03:21 PM
Convert litres per 100km to miles per gallon easily Ann Cardus Excel Discussion (Misc queries) 4 August 16th 05 03:39 PM
excel to figure miles per gallon Terri New Users to Excel 5 January 9th 05 06:59 PM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"