Private Sub cmdBuildTable_Click()
Dim asSelected() As String
Dim chkMyCheck As Control
Dim lRowCount As Long
Dim myRange As Range
Dim tblMyTable As Table
Dim lItem As Long
'Create an array to store the selected options
ReDim asSelected(1) As String
'loop through the controls..
For Each chkMyCheck In Me.Controls
'..looking for checkboxes...
If Left(chkMyCheck.Name, 3) = "chk" Then
'...that are checked....
If chkMyCheck.Value Then
'....and adding them to the array
asSelected(UBound(asSelected)) = chkMyCheck.Caption
'Then increasing the size of the array by 1
ReDim Preserve asSelected(UBound(asSelected) + 1) As String
End If
End If
Next chkMyCheck
'Make sure the array has an even number of elements by
'removing the extra record if there are an odd number
'of elements
If UBound(asSelected) Mod 2 = 1 Then
ReDim Preserve asSelected(UBound(asSelected) - 1) As String
End If
'Determine how many rows to put in the table
lRowCount = UBound(asSelected) / 2
'Add a new table, with the correct number o frows and 2 columns
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
Set tblMyTable = ActiveDocument.Tables.Add(Range:=myRange, NumRows:=lRowCount, NumColumns:=2)
'loop through the array - adding the values to the table
For lItem = LBound(asSelected) To UBound(asSelected)
'First we fill the first column
If lItem <= lRowCount Then
tblMyTable.Cell(lItem, 1).Range.InsertAfter asSelected(lItem)
'then we fill the second column
Else
tblMyTable.Cell(lItem - lRowCount, 2).Range.InsertAfter asSelected(lItem)
End If
Next lItem
'then close the form
Unload Me
End Sub