Counting checkboxes in a word document

P

Paula

I have a terrific form I've created, but it has a ton of checkboxes, and I
need to count which ones have been checked out of a certain group (some are
"yes", some "no" and some "n/a"). I need to count how many are checked in
each group so I can do a formula to determine what percent is in each
category. Any thoughts.
 
C

Chuck Henrich

Are you talking about a document form or a user form? If a document form,
how are you "grouping" them? By section?

In any case, here's example code that counts all checkboxes (form field type
71) as well as those that are checked, calculates the percentage checked and
displays a message. You'd need to modify the code to count checkboxes group
by group.

Sub CountCheckedBoxes()

Dim fldCheck As FormField
Dim x As Long
Dim y As Long
Dim z As String

x = 0
y = 0

For Each fldCheck In ActiveDocument.FormFields
If fldCheck.Type = 71 Then 'is checkbox
x = x + 1
If fldCheck.CheckBox.Value = True Then
y = y + 1
End If
End If
Next fldCheck

z = Format(y / x, "Percent")

MsgBox "There are " & x & " checkboxes on this form and " & _
y & _
" (" & z & ") " & _
"is/are checked."

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top