Hi Martin
The code is earlier in the thread, in my news reader it's the very first response to your
post. Here's the post again (including the code) in full:
Since only tables have rows, when you say <I want the Macro to find all the Tables with
the text “Response” and if the Row immediately above is Empty> to mean the paragraph
preceding the table. If that's the case then this should do the trick:
Public Sub SearchInTables()
Dim tblTemp As Word.Table
Dim rngParaBeforeTable As Word.Range
' Do this for ALL tables in the document
For Each tblTemp In ActiveDocument.Tables
' Setup for the search
With tblTemp.Range.Find
.ClearFormatting
.Text = "Response"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
' Find the required text
If .Execute Then
' Locate the paragraph before the table
Set rngParaBeforeTable = tblTemp.Range
rngParaBeforeTable.Collapse wdCollapseStart
rngParaBeforeTable.MoveStart wdParagraph, -1
rngParaBeforeTable.MoveEnd wdCharacter, -1
' Is the paragraph before the table empty (or contains just white space)
If LenB(Trim$(rngParaBeforeTable.Text)) = 0 Then
' Set range to include preceding paragraph, table and
' terminating paragraph mark
rngParaBeforeTable.End = tblTemp.Range.End
rngParaBeforeTable.MoveEnd wdParagraph, 1
' Delete paragraph before table and the table itself
rngParaBeforeTable.Text = vbNullString
End If
End If
End With
Next
End Sub ' SearchInTables
I've actually coded it, so that if the paragraph preceding the table is empty or contains
"white space" it will be deleted.
HTH + Cheers - Peter
Hi Peter,
I have searched, tested and amended a lot of the suggestions posted. Please
direct me where I may find your code.
Kind regards,
Martin
HTH + Cheers - Peter