Need Macro to Delete Ranges of Text

R

Robert Woodall

I receive a veryl large text file regularly that contains ranges of data
that I'd like to delete. Here's what I do manually; I know the text that
begins the range of data I want to remove so I use the Find feature to
locate it. I click and drag to the end of the data I don't need and then
press the Del key to remove it (fortunately, it is a continuous range!).
To continue, I'd use the find Feature again and repeat the process.
Since this is a very large file, How do I automate this process to find
each instance of the beginning text, select to the end of the data I
don't need, and delete it?

Thanks for the help!
--
God Bless and Take Care!

PEACE!

Rob
 
J

Jezebel

A macro to find the start of your ranges is simple enough; but how do you
recognise the end of the range you want to delete? Are you looking for a
second piece of text?
 
R

Robert Woodall

I'm sorry for the confusion. I also know the ending text in the range of data
I want to delete. The file I receive is a listing of tv/movie programs and
each program includes a range of data I don't need. Fortunately, the unneeded
data is marked with the same text at its beginning and end. That's how I know
how to do the find text feature. And since the end of the unneeded data is the
same for each program, I also know how far to click and drag and than delete.
This was an easy VB task for me to do in Excel, I can't figure it out in Word.
Thanks again!
A macro to find the start of your ranges is simple enough; but how do you
recognise the end of the range you want to delete? Are you looking for a
second piece of text?

--
God Bless and Take Care!

PEACE!

Rob
 
K

Klaus Linke

Hi Robert,

You can use Find/Replace with wildcards.

To delete everything from A to B (including A and B):
Find what: A*B
Replace with:

To delete everything from A to B (excluding A and B):
Find what: (A)*(B)
Replace with: \1\2

Especially if A and B are the same (which seems to be the case for you),
using the wildcard * (any text) is very risky.
If there is one "tag" A too many, or one missing, you may end up deleting
what you want to keep (and vice versa).

It'll be much safer though if you can put some more restrictions on the
text that is going to be deleted.
If it doesn't contain paragraph marks, for example, use [!^13]@ instead of
*:
Find what: A[!^13]@B
Replace with:

The macro recorder should give you some code to work with.

For more info on wildcards, see the Word help and/or
http://word.mvps.org/FAQs/General/UsingWildcards.htm

Good luck,
Klaus
 
R

Robert Woodall

Klaus!

You're a God send! Amazing how such an involved task can involve such a simple
operation. Your suggestions worked exactly as I needed. This find/replace
method has reduced my doc size from over 2800 pages to less than 450 pages (by
Word's estimates). That's the danger of thinking too much like a spreadsheet
designer in a doc environment : O

Thanks Again!

Klaus said:
Hi Robert,

You can use Find/Replace with wildcards.

To delete everything from A to B (including A and B):
Find what: A*B
Replace with:

To delete everything from A to B (excluding A and B):
Find what: (A)*(B)
Replace with: \1\2

Especially if A and B are the same (which seems to be the case for you),
using the wildcard * (any text) is very risky.
If there is one "tag" A too many, or one missing, you may end up deleting
what you want to keep (and vice versa).

It'll be much safer though if you can put some more restrictions on the
text that is going to be deleted.
If it doesn't contain paragraph marks, for example, use [!^13]@ instead of
*:
Find what: A[!^13]@B
Replace with:

The macro recorder should give you some code to work with.

For more info on wildcards, see the Word help and/or
http://word.mvps.org/FAQs/General/UsingWildcards.htm

Good luck,
Klaus

Robert Woodall said:
I'm sorry for the confusion. I also know the ending text in the range of data
I want to delete. The file I receive is a listing of tv/movie programs and
each program includes a range of data I don't need. Fortunately, the unneeded
data is marked with the same text at its beginning and end. That's how I know
how to do the find text feature. And since the end of the unneeded data is the
same for each program, I also know how far to click and drag and than delete.
This was an easy VB task for me to do in Excel, I can't figure it out in Word.
Thanks again!


--
God Bless and Take Care!

PEACE!

Rob

--
God Bless and Take Care!

PEACE!

Rob
 

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