View Single Post
 
Old 06-27-2019, 06:34 AM
JellehFishh JellehFishh is offline Windows 7 64bit Office 2010
Novice
 
Join Date: Jun 2019
Posts: 5
JellehFishh is on a distinguished road
Default Macro to delete table rows based on the absence of a single specific keyword

Hi all,

I don't have any VBA training but I like to scour the internet to try Frankenstein macros that suit my needs.

I need a macro that will search a table and delete ALL rows that DO NOT contain a single consistent and unchanging keyword (in column 4).

I have the following that seems to reliably delete ALL rows that DO contain the keyword but I can't seem to invert the function.

Thank you!


Sub DeleteRowsKEYWORD()

Dim TargetText As String
Dim oRow As Row

If Selection.Information(wdWithInTable) = False Then Exit Sub

TargetText = "KEYWORD"

For Each oRow In Selection.Tables(1).Rows
If oRow.Cells(4).Range.Text = TargetText & vbCr & Chr(7) Then oRow.Delete
Next oRow

End Sub
Reply With Quote