Calculating check boxes

D

Don

I have a several columns of check boxes in a table and would like to total
the number of “True†boxes for each column. Can this be done?
 
G

Greg Maxey

Don,

Yes it can by using macros. I am a novice with VBA and rusty to boot, but
here is an example of code to tally the results of check boxes in columns 2,
3, 4, and 5 (I used labels b, c, d, e) of a table that might get you
started. You will need to insert text fields in the last row of the columns
bookmarked as indicated in the code to hold the results.

If you have further problems you might want to post in the VBA beginner or
general group where the heavies hang out.

Sub TallyResults()

Dim bTotal As Integer, cTotal As Integer, dTotal As Integer, eTotal As
Integer

bTotal = 0
cTotal = 0
dTotal = 0
eTotal = 0

For i = 1 To ActiveDocument.Tables(1).Rows.Count
On Error Resume Next
bTotal = bTotal - ActiveDocument.Tables(1).Cell(i,
2).Range.FormFields(1).CheckBox.Value
cTotal = cTotal - ActiveDocument.Tables(1).Cell(i,
3).Range.FormFields(1).CheckBox.Value
dTotal = dTotal - ActiveDocument.Tables(1).Cell(i,
4).Range.FormFields(1).CheckBox.Value
eTotal = eTotal - ActiveDocument.Tables(1).Cell(i,
5).Range.FormFields(1).CheckBox.Value

Next i
ActiveDocument.FormFields("bTotal").Result = bTotal
ActiveDocument.FormFields("cTotal").Result = cTotal
ActiveDocument.FormFields("dTotal").Result = dTotal
ActiveDocument.FormFields("eTotal").Result = eTotal

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