Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2019, 06:34 AM
JellehFishh JellehFishh is offline Macro to delete table rows based on the absence of a single specific keyword Windows 7 64bit Macro to delete table rows based on the absence of a single specific keyword Office 2010
Novice
Macro to delete table rows based on the absence of a single specific keyword
 
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
  #2  
Old 06-27-2019, 07:17 AM
gmaxey gmaxey is offline Macro to delete table rows based on the absence of a single specific keyword Windows 10 Macro to delete table rows based on the absence of a single specific keyword Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
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 InStr(oRow.Cells(4).Range.Text, TargetText) = 0 Then oRow.Delete
  Next oRow
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-27-2019, 08:23 AM
JellehFishh JellehFishh is offline Macro to delete table rows based on the absence of a single specific keyword Windows 7 64bit Macro to delete table rows based on the absence of a single specific keyword Office 2010
Novice
Macro to delete table rows based on the absence of a single specific keyword
 
Join Date: Jun 2019
Posts: 5
JellehFishh is on a distinguished road
Default

Does exactly what I need it to, thanks!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete table rows based on the absence of a single specific keyword Design Macro or Code to Delete Table Rows When Null/Blank/Empty Upon Doc Close/Save aaghd72 Word VBA 8 02-18-2019 11:22 AM
Macro to delete table rows based on the absence of a single specific keyword Macro delete table rows if cell in first column = $ Btop Word VBA 7 02-13-2018 05:36 PM
Automatically delete row based on keyword-VBA yoyo4 Excel Programming 4 12-06-2017 06:10 AM
Macro to delete table rows based on the absence of a single specific keyword Excel VBA macro to copy specific rows and delete it pourmalla Excel Programming 2 04-02-2017 12:09 AM
Macro to delete table rows based on the absence of a single specific keyword Macro to delete rows not containing specific text Alimou Excel Programming 4 02-06-2017 07:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft