Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

count the value of Optionbox in a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
frogman - 10 Aug 2006 16:54 GMT
I have a table with 5 columns
Step   Action   Expected Results   Pass    Fail

in the pass fail columns there are option boxes.  I want to count the
number of passes and the number of fails to total them with out counted
every cell.  Hopefully there is a loop i can use.
Jonathan West - 10 Aug 2006 18:17 GMT
>I have a table with 5 columns
> Step   Action   Expected Results   Pass    Fail
>
> in the pass fail columns there are option boxes.  I want to count the
> number of passes and the number of fails to total them with out counted
> every cell.  Hopefully there is a loop i can use.

The following code assumes that you put an X in the relevant cells to
indicate a pass or a fail

Dim oCol As Column
Dim oCell As Cell
Dim iPass As Long
Dim iFail As Long

'Count the passes
For Each oCell In ActiveDocument.Tables(1).Columns(4).Cells
 If Asc(oCell.Range.Text) = Asc("X") Then
   iPass = iPass + 1
 End If
Next

'Count the fails
For Each oCell In ActiveDocument.Tables(1).Columns(5).Cells
 If Asc(oCell.Range.Text) = Asc("X") Then
   iFail = iFail + 1
 End If
Next
MsgBox iPass & " passes" & vbCr & iFail & " fails"

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

frogman - 10 Aug 2006 19:36 GMT
I got that to work the reason I wanted to use Optionsboxes is that I
want to total the fields if one of the pass fail it changed.
Greg Maxey - 11 Aug 2006 03:00 GMT
Frogman,

Thanks to some great detective work by Jay Freedman, I think I can
offer some help.
If you name all of your Pass optionbuttons Pass1, Pass2, etc. and the
Fail buttons Fail1, Fail 2, etc. then you could get a count of the
active buttons of each type using something like:

Sub CountSelectedOptionBoxes()
Dim ctl As InlineShape
Dim i As Double
Dim j As Double
For Each ctl In ActiveDocument.InlineShapes
 If ctl.Type = wdInlineShapeOLEControlObject Then
   If InStr(ctl.OLEFormat.Object.Name, "Pass") > 0 Then
     i = i + ctl.OLEFormat.Object.Value
   ElseIf InStr(ctl.OLEFormat.Object.Name, "Fail") > 0 Then
     j = j + ctl.OLEFormat.Object.Value
   End If
 End If
Next
MsgBox "Pass: " & -i & "Fail: " & -j
End Sub

> I got that to work the reason I wanted to use Optionsboxes is that I
> want to total the fields if one of the pass fail it changed.
frogman - 11 Aug 2006 18:48 GMT
Thanks that works like a charm.

The only thing i had to change was the names of my pass fail labels.
Just a note you can only have the Pass Fail keywords in the objects you
want to try to count and no where else.

On to big and better things

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.