With help from the experts at this forum, I crafted the following macro to search for a specific text string. If the text is found within a table, the row is deleted.
Would you help me further restrict this code to only look in the first row and the last row of all tables? I am certainly okay with running two macros if that is less complicated.
Thank you in advance for considering my request for help.
Code:
Sub DeleteRowIf()
Application.ScreenUpdating = False
Dim MyRange As Range
Set MyRange = ActiveDocument.Range
With MyRange.Find
.ClearFormatting
.Text = "TEXT TO FIND"
.MatchCase = True
.Forward = True
.Wrap = wdFindStop
.Format = False
While .Execute
If MyRange.Information(wdWithInTable) Then
MyRange.Rows(1).Delete
End If
Wend
End With
Application.ScreenUpdating = True
Application.ScreenRefresh
MsgBox "Done!", vbInformation
End Sub