Jean,
Thanks for the reply
SEE NOTE at the end of this entry ...
Empty (in this instance) meaning -- Say I have several tables in my
template, and from a From, the user will make various selections which will
populate rows in some (but not all) of the tables. I need code which will
examine these tables and delete any rows having not data (ie -- no data
populated by the Forms)
========================================
Jean -- this is a continuation of the project/issue you helped me with back
in Nov -- I just need to clean up the empty rows now (see your original code
below)
Something like this (combining the code from above):
'_______________________________________
Sub DelTablesAndAddSum()
Const strBookRoot As String = "Table"
Const strCode1 As String = "=SUM("
Const strCode2 As String = ") \# ""#,##0.00;- #,##0.00;''"""
Dim strCodeInsert As String
Dim rgeCell As Range
Dim i As Long
Dim tblsDocument As Tables
Set tblsDocument = ActiveDocument.Tables
'Here we take for granted that the summary table has more than 3 rows
For i = tblsDocument.Count To 1 Step -1
If tblsDocument(i).Rows.Count < 4 Then
tblsDocument(i).Delete
End If
Next
'If only one table left, it is the Summary table, no need to continue
If tblsDocument.Count = 1 Then Exit Sub
'Skip summary table...
For i = 1 To tblsDocument.Count - 1
ActiveDocument.Bookmarks.Add strBookRoot & CStr(i),
tblsDocument(i).Range
'Building string to add all cells in the fourth column of all tables
strCodeInsert = strCodeInsert & strBookRoot & CStr(i) & " D
, "
Next
'remove extra ", " from string
strCodeInsert = Left(strCodeInsert, Len(strCodeInsert) - 2)
'Set range where to insert field code
Set rgeCell = tblsDocument(i).Cell(4, 4).Range
rgeCell.Collapse wdCollapseStart
'Insert field code in forth cell of fourth row of last table in document
'Presumed to be the summary table
ActiveDocument.Fields.Add rgeCell, wdFieldEmpty, _
strCode1 & strCodeInsert & strCode2, False
End Sub
'_______________________________________