![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]() Quote:
abcd1234WAS or abcd1234WERE But the paragraphs or rows that only have abcd1234, I need to remove. Thanks |
#4
|
||||
|
||||
![]()
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 |
#5
|
|||
|
|||
![]()
That works perfectly gmayor! thanks
|
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Jamal NUMAN | Word | 2 | 04-28-2017 12:59 PM |
![]() |
Bathroth | Word VBA | 1 | 10-01-2014 01:40 PM |
![]() |
gbaker | Excel Programming | 18 | 07-21-2014 04:51 AM |
![]() |
dennist77 | Word | 1 | 10-29-2013 11:39 PM |
![]() |
Learner7 | Excel | 1 | 04-19-2011 02:45 AM |