Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-25-2017, 10:17 PM
macropod's Avatar
macropod macropod is offline Counting items in the table Windows 7 64bit Counting items in the table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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



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 items in the table 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 items in the table 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft