![]() |
|
#2
|
||||
|
||||
|
If you save the document in the docm format, the following macro added to the documents 'ThisDocument' code module will update the second table any time you exit a content control in the first table.
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim Tbl1 As Table, Tbl2 As Table, r As Long, i As Long, j As Long
If CCtrl.Title Like "Name#" Then
Set Tbl1 = ActiveDocument.Tables(1)
Set Tbl2 = ActiveDocument.Tables(2)
With Tbl2
For r = 2 To .Rows.Count
.Cell(r, 2).Range.Text = 0
Next
End With
With Tbl1
For r = 1 To .Rows.Count
With .Cell(r, 1).Range.ContentControls(1).Range
If .Text Like "Position #" Then
i = CLng(Split(.Text, " ")(1)) + 1
j = CLng(Split(Tbl2.Cell(i, 2).Range.Text, vbCr)(0))
Tbl2.Cell(i, 2).Range.Text = j + 1
End If
End With
Next
End With
End If
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lock items in a table | village | Word | 2 | 06-22-2017 07:33 AM |
| Counting Occurance using Pivot Table | MaineLady | Excel | 9 | 08-16-2016 09:16 AM |
Counting table rows in a page
|
RavenSuzumiya | Word Tables | 1 | 06-09-2016 03:38 PM |
| Counting unique visitors by ward, counting monthly visits by status, editing existing workbook | JaxV | Excel | 9 | 11-14-2014 12:25 AM |
Counting how many times a table or a field of a table is used in a document
|
moose5267 | Word Tables | 1 | 08-15-2014 01:41 AM |