![]() |
|
|
|
#1
|
|||
|
|||
|
I have a table in Word 2007 and 2013 with several columns that have FF Check Boxes in them. I would like to total the number of boxes that are checked. I've tried the following, but they don't work: =COUNTIF(A3:A13,TRUE), =Sum(A3:A13,TRUE). Could someone please give me a formula that will total the checked boxes?
|
|
#2
|
||||
|
||||
|
Word is not Excel, so you won't be able to do this with Excel functions.
You will need a macro. As you already propose using a macro to colour the fields then you could use a macro to calculate the column count. The only proviso is that there must not be split or merged cells in the table or the code will not work. No doubt you can call this macro from the other macro to update the count on exit from each field. The macro will count the checked boxes in each column and add the total to the last row of that column. Code:
Sub CountCheckBoxes()
Dim oTable As Table
Dim oCell As Cell
Dim oFF As FormField
Dim iCount As Long, iField As Long
Dim oCol As Column
Dim bProtected As Boolean
'Unprotect the file
If Not ActiveDocument.ProtectionType = wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
Set oTable = ActiveDocument.Tables(1)
For Each oCol In oTable.Columns
iCount = 0
iField = 0
For Each oCell In oCol.Cells
For Each oFF In oCell.Range.FormFields
If oFF.Type = wdFieldFormCheckBox Then iField = iField + 1
If oFF.CheckBox.Value = True Then iCount = iCount + 1
Next oFF
Next oCell
If iField > 0 Then oCol.Cells(oTable.Rows.Count).Range.Text = CStr(iCount)
Next oCol
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=""
End If
lbl_Exit:
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thanks again gmayor.
|
|
| Tags |
| check box, countif, table |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to make a Check Box Form Field red if not checked?
|
CarlCR | Word Tables | 3 | 07-12-2016 08:35 PM |
| Check Box Content Control when checked users are presented with an option | cryder | Word | 0 | 01-07-2016 05:11 AM |
Check box form field automatically checked
|
Eduardo Care | Word | 8 | 09-07-2015 03:31 PM |
| how to show total of check boxes checked | worder | Word | 16 | 03-10-2014 05:07 PM |
Repeat Spell check in a doc that has already been checked
|
mawigfie | Word | 1 | 08-22-2012 01:16 PM |