Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2017, 09:04 AM
ewso ewso is offline remove rows without certain word Windows 10 remove rows without certain word Office 2016
Advanced Beginner
remove rows without certain word
 
Join Date: Nov 2016
Posts: 80
ewso is on a distinguished road
Default remove rows without certain word

I have several rows in a document that don't contain certain words and I need to remove them all and keep only the rows with the words. The two words are WERE and WAS. The words are often pressed up against other words in the row, like this...



abcdWASabcd
abcdWEREabcd

It's ok for the rows to be like that, but I need to remove every row that doesn't contain those words. The rows are not in a table. It's just a bunch of rows of text.
Can this be done with a macro?

Thanks
Reply With Quote
  #2  
Old 05-27-2017, 08:25 PM
gmayor's Avatar
gmayor gmayor is offline remove rows without certain word Windows 10 remove rows without certain word Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,829
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

By 'rows' I assume that you mean paragraphs? In theory this could be done with a macro, but not without knowing what else is in the document. For example you say that the words are often 'pressed up' against other words like those shown, which implies that sometimes they are not. What if they are legitimate parts of other words - like 'WASTREL' or "WASH"? This question requires more detail or a document example.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-27-2017, 11:18 PM
ewso ewso is offline remove rows without certain word Windows 10 remove rows without certain word Office 2016
Advanced Beginner
remove rows without certain word
 
Join Date: Nov 2016
Posts: 80
ewso is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
By 'rows' I assume that you mean paragraphs? In theory this could be done with a macro, but not without knowing what else is in the document. For example you say that the words are often 'pressed up' against other words like those shown, which implies that sometimes they are not. What if they are legitimate parts of other words - like 'WASTREL' or "WASH"? This question requires more detail or a document example.
Gmayor, yes they are paragraphs. Each of the paragraphs or rows only take up about half of a line and go down the whole document. Sometimes the words are on their own and some times they are pressed against other letters or numbers, though they are never pressed together with other letters to make legitimate words like wastrel or wash. It's almost always numbers the words are pressed against like this...

abcd1234WAS or abcd1234WERE

But the paragraphs or rows that only have abcd1234, I need to remove.

Thanks
Reply With Quote
  #4  
Old 05-28-2017, 12:22 AM
gmayor's Avatar
gmayor gmayor is offline remove rows without certain word Windows 10 remove rows without certain word Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,829
gmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to beholdgmayor is a splendid one to behold
Default

In that case
Code:
Sub Macro1()
Dim oPara As Paragraph
    For Each oPara In ActiveDocument.Paragraphs
        If InStr(1, oPara.Range.Text, "WAS") = 0 And _
           InStr(1, oPara.Range.Text, "WERE") = 0 Then
            oPara.Range.Delete
        End If
    Next oPara
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 05-28-2017, 01:27 AM
ewso ewso is offline remove rows without certain word Windows 10 remove rows without certain word Office 2016
Advanced Beginner
remove rows without certain word
 
Join Date: Nov 2016
Posts: 80
ewso is on a distinguished road
Default

That works perfectly gmayor! thanks
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove rows without certain word How to remove blank spaces between rows in a table, Jamal NUMAN Word 2 04-28-2017 12:59 PM
remove rows without certain word Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM
remove rows without certain word Remove rows less than 10 gbaker Excel Programming 18 07-21-2014 04:51 AM
remove rows without certain word Grouping table rows to prevent individual rows from breaking across pages dennist77 Word 1 10-29-2013 11:39 PM
remove rows without certain word How to remove blank rows from a specified range? Learner7 Excel 1 04-19-2011 02:45 AM

Other Forums: Access Forums

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


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