Macro using a Loop

A

Ann

Hi all! I am working on creating a macro to delete
information in a report. I have a header section and
under that I have client information. I need to delete
the first 18 characters of each line for confindentiality
reasons. The number of clients varies per report, so
there is not a constant number of lines. If I only need
to delete one line, I could have the macro find a certain
word in the report, go to the start of the line to be
deleted, select the characters to be deleted, and delete
that section, but I have multiple lines. I want to do a
loop, but I am not sure how I should do this. Does
anyone have any suggestions? Thanks in advance.

Ann
 
E

Ed

If I read your post correctly, the same word is in each line containing
characters that need to be deleted. If so, then the following code may work
for you. Put your "target word" in the appropriate place. I'm sure there
are other ways of doing this, but I found that making the
Selection.Find.Execute part of the loop, and basing actions on If .Found =
True Then gave me the fewest errors.

HTH
Ed

Selection.Find.ClearFormatting

With Selection.Find

.Text = "YOUR TEXT TO FIND HERE"

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindStop

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With



Do

Selection.Find.Execute



If Selection.Find.Found = True Then

Selection.MoveLeft Unit:=wdCharacter, Count:=1

Selection.MoveRight Unit:=wdCharacter, _

Count:=18, Extend:=wdExtend

Selection.Delete Unit:=wdCharacter, Count:=1

Else

Exit Do

End If

Loop
 
A

Ann

Hi Ed,

There is a three letter constant at the first of each
line, the only thing is that three letter combination can
also be found in the clients name. If my constant
is "ABC" and do a loop using this text, it will also pull
in the "ABC" combo if it is in the client name. Thus, my
information will not be accurate. For Example:

Constant Client name
ANN ANN ANYONE
ANN XYZ ANYONE

The loop will pull the ANN from the constant and client
name. Do you have any suggestions on how to avoid this?
Thanks in advance.

Ann
 
E

Ed

Try a search for a paragraph mark and your constant: "^pABC" and see if that
works.

Ed
 

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