View Single Post
 
Old 03-16-2013, 01:35 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Hi Elan05,


The code works OK in my testing, but it relies on there being only one formfield per row. That's because, having got a row count, it then proceeds to apply that to a count of formfields. So, if your table has 10 rows, with two formfields per row, but only the formfields in the first 5 rows are completed, no rows will be deleted.

Also, as coded, the macro doesn't stop at the first row containing a filled formfield - within the above limitations it tests every row and, if it doesn't find a filled formfield there, deltes the row. That means it will also delete rows that have no formfields (eg a header row).

Try the following:
Code:
Sub DeleteEmptyRows()
'Delete empty rows in the table after all equipment has been entered
Application.ScreenUpdating = False
Dim StrPwd As String
StrPwd = "a"
With ActiveDocument
  .Unprotect Password:=StrPwd
  With .Tables(1).Rows
    While .Last.Range.FormFields(1).Result = ""
        .Last.Delete
    Wend
  End With
  .Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=StrPwd
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote