Průměrná hodnota pole

Funkce:
'Parametry FIRST a LAST indikují, kterou část pole zpracovat. 
'Pokud nejsou zadány, bere se celé pole. 
'Pokud je parametr IGNOREEMPTY = True nebo není zadán, 
'prázdné hodnoty se vynechávají 

Function ArrayAvg(arr As Variant, Optional First As Variant, _ 
   Optional Last As Variant, _
   Optional IgnoreEmpty As Boolean = True) As Variant 

   Dim index As Long 
   Dim sum As Variant 
   Dim count As Long 

   If IsMissing(First) Then First = LBound(arr) 
   If IsMissing(Last) Then Last = UBound(arr) 

   'Pokud arr není pole, vygeneruje se chyba 
   For index = First To Last 
      If IgnoreEmpty = False Or Not IsEmpty(arr(index)) Then 
         sum = sum + arr(index) 
         count = count + 1 
      End If 
   Next 

   ArrayAvg = sum / count 

End Function

Zpět

Autor: The Bozena