View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Melanie Breden Melanie Breden is offline
external usenet poster
 
Posts: 88
Default Excel - VBA sub routine to get AVG

I had developed a sub routine that sums a range of cells M12:M40 that
depended on whether or not a checkbox value was true for that
particular cell.
What I would like to be able to do is take that sum and then get an
average based on those checkboxes that are checked.


here is the extension of my code:

Sub AverageCheckBoxes()
Dim obj As OLEObject
Dim dblValue As Double
Dim intCount As Integer

For Each obj In ActiveSheet.OLEObjects
If obj.progID = "Forms.CheckBox.1" And obj.Object.Value Then
dblValue = dblValue + Range _
("M" & VBA.Replace(obj.Name, "CheckBox", "") + 11).Value
intCount = intCount + 1
End If
Next obj

MsgBox dblValue / intCount
End Sub

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)