I am creating a document where the users will enter information in a table. I created a macro that allows the user to add rows as needed. I am trying to create a second macros that will run when the user exits the end of the table that will delete any rows that have all blank form fields.
I found this on another forum. I sent it to run when exiting the last form field of the table, the document flashes a few times so I can tell that it is running something but the blank rows did not delete. I am also not getting an error message. Can anyone help? What am I missing?!
Code:
Sub DeleteEmptyRows()
'
'Delete empty rows in the table after all equipment has been entered
'
ActiveDocument.Unprotect Password:="a"
Counter = ActiveDocument.Tables(1).Rows.Count
While Counter > 0
If ActiveDocument.FormFields(Counter).Result = "" Then
ActiveDocument.Tables(1).Rows(Counter).Delete
End If
Counter = Counter - 1
Wend
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="a"
End Sub