Delete to a "find" point

R

Riptide55

Is it possible to delete text up to a Find command? I'd like to write a macro
that says "Delete all text until you Find xxxx". For instance if I have the
word FINDME multiple times in text I would like to turn on delete until the
Find command reaches FINDME, then deletes all the characters between where
the Find command started and found the word. I could then arrow down to the
next line and start a loop command to keep the macro running to the end of
the document. I know this is complicated but I would really appreciate
knowing if I can do it.
 
D

Doug Robbins - Word MVP

A macro containing the following code will delete everything from the
current position of the cursor up to and including the word FILEME

Dim rngdelete As Range
Set rngdelete = Selection.Range
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Text = "FINDME"
.MatchCase = True
.MatchWildcards = False
.Execute
End With
rngdelete.End = Selection.Range.End
rngdelete.Delete


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
P

Pesach Shelnitz

Hi,

Actually, you don't need a macro to do this. Place your cursor at the
beginning of the block that you want to select for deletion, press F8, and
then press Ctrl+F. Type FINDME (or any other search string), click OK (or
press Enter), and then press Delete.

If you don't delete the selection, press Esc to cancel the extending effect
of the F8 key.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top