Thread: average on qty
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tajin[_2_] Tajin[_2_] is offline
external usenet poster
 
Posts: 3
Default average on qty

I am trying to make a function that makes the average of number of inputs
based on a bigger input qty array, to keep dividing by the same number l need
to throw out of the sum the lowest index to divide by the same number, this
is part of the code I have but I don't know how to make an array output, it
does not work.

Function my_avg(data(), j As Integer) As Double

' Function passes an array of data(), and returns an array of data after
' calculates my_avg, which is the sum of data divided by number of data
' my_avg begins with a sum of one data up to a max of j, if data input is
' higher than j, division will be done to j, and sum will throw out the
' lower index.

my_avg = 0

For i = 0 To UBound(data)
If i < 15 Then
my_avg = (my_avg + data(i)) / (i + 1)
If i = 15 Then
my_avg = (my_avg + data(i)) / j
If i 15 Then
my_avg = (my_avg + data(i) - data(i - 15)) / j
End If
Next i
End Function

--
Tajin