Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel - VBA sub routine to get AVG

Hello,

I had developed a sub routine that sums a range of cells M12:M40 tha
depended on whether or not a checkbox value was true for tha
particular cell.

I.E. There are 29 cells between M12 and M40 and there is a Checkbo
associated with each cell labled CheckBox1 to CheckBox29.

What I would like to be able to do is take that sum and then get a
average based on those checkboxes that are checked.

Here is my code:


Private Sub SumCheckBoxes_Click()

Dim obj As OLEObject
Dim dblValue As Double

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
End If
Next obj

'MsgBox dblValue
Sheets("Step 5").Range("M43") = dblValue

End Sub


What I need is some way to count the number of cells that have thei
checkbox value set to true then divide that number by the sum from th
code above.

How could I go about this? Any ideas?

Thanks for any help I can ge

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
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)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel - VBA sub routine to get AVG

Thanks Melanie!

My problem was in the placing of this line:

intCount = intCount + 1.

But now it works

Thanks for your time and suggestion, it works perfectl

--
Message posted from http://www.ExcelForum.com

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
interpolation routine for Excel Steve Excel Worksheet Functions 10 November 19th 08 06:52 PM
Converting a Access routine into an Excel macro? turtle[_2_] Excel Discussion (Misc queries) 2 February 21st 07 06:38 PM
how can I use excel to automatically generate routine report? scott Excel Worksheet Functions 0 December 29th 05 09:02 PM
Help: a routine for launching an allarm in excel John Milton Excel Programming 1 September 26th 03 09:41 PM
Need VBA Routine John M. Lembo Excel Programming 0 July 13th 03 01:51 AM


All times are GMT +1. The time now is 11:59 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"