Solved: Word Macro Loop of 1) Find 2)Select line 3)Delete line 4)find.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Smilylex

Thread Starter
Joined
Apr 11, 2013
Messages
24
Hello

I have a need to find a text of X in a document go to end of line select whole line and delete line and then find next X in document. With 3500 X Id like to loop till end of document. In 2010 my (pc at home) the find X part of a recorded Macro does not show up. In 2007 it shows up so I can see how it works at office. I just need to know how to loop, the above of instruction "find X, select whole line, delete, find next X" and loop this.

Eg

YYYY 1
AHKJUSKL XX
AGSJUJ ()*(IO XX
ASJ
L:JOPO
AKLSJXX
DADAD

needs to look like

YYYY 1
ASJ
L:JOPO
DADAD

using XX as the reference of which line to delete.



Cheers
Al
 
Joined
Feb 21, 2013
Messages
520
try this on a copy of your file.

Code:
Sub Macro1()
'
Range("A1").Select
Do
On Error GoTo 999
    Cells.Find(What:="xx", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).EntireRow.Delete
        
Loop
999 MsgBox ("all occurrences have been deleted")
End Sub
 
Joined
Sep 4, 2003
Messages
4,912
The macro you posted is for Excel not Word like the original poster requested. The code below should work

Code:
Sub DeleteLines()

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Text = "XX"
Do While Selection.Find.Execute = True
Selection.HomeKey Unit:=wdLine
Selection.MoveEnd Unit:=wdLine
Selection.Delete
Loop
End Sub



Rollin
 

Smilylex

Thread Starter
Joined
Apr 11, 2013
Messages
24
Solved Many Thanks I'll post solution next week when back from Holidays.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top