Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to? running average from a variable length list

I am a baseball nut... I have a spreadsheet which tracks ML Baseball and
generates charts and stats. One thing I want to do is maintain a running
'last 10 games' average for each team. The problem is, the way the data is
arrainged in the sheet - by calendar days - every week or so a team has a
day off [or there's the 3 day all star break], so using a strianght AVG or
SUM to find how many wins in the last 10 rows results in inaccuracies in the
count. I could program a VB button to do it programatically, but how would
I make it auto calculate with the sheet, so I dont have to push a button?
Or.. is there any way to make an existing excel function calculate an
average based on a conditionally variable length list... right now in the
wins column a 1 is a win, a 0 is a loss and non playing days are represented
with a text 'ng'. Any help from you folk more guru-like than myself would be
apreciated.. I can post an excellent baseball tracking file...


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default how to? running average from a variable length list

Rob,

The easiest way is to use a user-defined-function. The code below should be put into a standard module in your workbook, and the
function can be used like:

=LastTenAvg(A:A)

to return the average of the last ten 0 / 1 values in column A. Note that if there aren't ten values, then the average of the
values currently entered is returned.

HTH,
Bernie
Excel MVP

Function LastTenAvg(inRange As Range) As Double
Dim myRange As Range
Dim lRow As Long
Dim myCount As Integer

Set myRange = Intersect(inRange, Application.Caller.Parent.UsedRange)

For lRow = myRange(myRange.Cells.Count).Row To 1 Step -1
If myRange(lRow).Value < "ng" Then
myCount = myCount + 1
LastTenAvg = LastTenAvg + myRange(lRow).Value
End If
If myCount = 10 Then
LastTenAvg = LastTenAvg / 10
Exit Function
End If
Next lRow

LastTenAvg = LastTenAvg / myCount

End Function




"robreeve" wrote in message news:i4yUa.133991$GL4.34911@rwcrnsc53...
I am a baseball nut... I have a spreadsheet which tracks ML Baseball and
generates charts and stats. One thing I want to do is maintain a running
'last 10 games' average for each team. The problem is, the way the data is
arrainged in the sheet - by calendar days - every week or so a team has a
day off [or there's the 3 day all star break], so using a strianght AVG or
SUM to find how many wins in the last 10 rows results in inaccuracies in the
count. I could program a VB button to do it programatically, but how would
I make it auto calculate with the sheet, so I dont have to push a button?
Or.. is there any way to make an existing excel function calculate an
average based on a conditionally variable length list... right now in the
wins column a 1 is a win, a 0 is a loss and non playing days are represented
with a text 'ng'. Any help from you folk more guru-like than myself would be
apreciated.. I can post an excellent baseball tracking file...




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
Variable Length Columns Gucktly Excel Discussion (Misc queries) 2 April 29th 10 07:32 PM
Variable Axis Length Krys Charts and Charting in Excel 2 July 1st 08 08:19 PM
Return a Variable value length Sean Excel Worksheet Functions 5 December 4th 06 09:25 PM
Transpose a variable length list into Excel / Access Table Pete New Users to Excel 11 September 13th 06 07:37 PM
Sum a column of variable length? Brian Excel Discussion (Misc queries) 5 February 3rd 05 02:26 PM


All times are GMT +1. The time now is 07:17 PM.

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

About Us

"It's about Microsoft Excel"