View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Take Up A Collection

Thanks!
--
Gary''s Student - gsnu201001


"Ryan H" wrote:

Is your collection a collection of range values? That's what I assumed. Not
sure if this is the easiest way, but it worked for me.
Sub test()

Dim coll As Collection

Set coll = New Collection
With coll
.Add Range("A1").Value
.Add Range("A2").Value
.Add Range("A3").Value
.Add Range("A4").Value
End With

MsgBox AvgCollection(coll)

End Sub

Function AvgCollection(col As Variant) As Double

Dim c As Variant
Dim dblSum As Double
Dim counter As Long

For Each c In col
dblSum = dblSum + c
counter = counter + 1
Next c

AvgCollection = dblSum / counter

End Function

--
Cheers,
Ryan


"Gary''s Student" wrote:

I have some code that is passed a Collection of positive values. What is the
easiest way to average the values ?
--
Gary''s Student - gsnu201001