View Single Post
 
Old 07-12-2016, 08:53 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote