Loop Question

S

Steved

Hello from Steved

The macro below does this

Find Prz, then Find F, turn on Extension and find .Size = 30 and .Bold =
True,
move up 2 while in extension and then delete.

Ok the issue is Do While .Execute

I have used the step through ( F8) and it works fine for the first but
second one I have a problem with Do While .Execute, Please where do I need to
place it so that it starts at the beginning each time please. I have posted
under the macro What I mean. Each starts with a number ie 1, 2 etc Thankyou.

Sub Test()
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Prz"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
With Selection.Find
.Text = "F"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find.Font
.Size = 30
.Bold = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True

Do While .Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Loop
End With
End Sub

1 x80x2 Invigorate (17) 4g blk
Colombia-Flight Hero (by Clay Hero) [Legally Blonde 5m(Magic Of Sydney)]
Laura Woods 57kg (R57)
Royal blue, white stars, red sleeves, emerald green armbands & cap
Stats:
Trainer: Peter Lock (Te Rapa)
Owner: Messrs G T Grant & P W Lock
All 4:0:1:0:0
Prz $1,000
F 0:0:0
G 1:0:0
D 1:0:1
S 1:0:0
H 1:0:0
C 0:0:0
Dst 0:0:0 F90 3:0:1:0
2Up 1:0:0:0
Fav 0:0:0:0
2 Fav 1:0:0:0
Win $0.00
Plc $0.66
Perf: STRA 31 Dec 2004 - 1st up 9 of 11 F-Mdn $6K 1200 S4.1 Hayden Tinsley
[53.5] 55 (7) 2/1 $4.50 1st: Monsanto 1:14.31 9.2L
DARG 11 May 2005 - 1st up 8 of 12 Mdn $6K 1200 G- Cameron Lammas [54.5] 56
(11) 6/5 $10.50 1st: Cheerful Star 1:11.99 5.4L
TAWA 01 Jun 2005 21 dys 2nd up 12 of 12 Mdn cg&e $5K 1150 H4.7 Lisa Cropp
[56] 56 (12) 7/7 $11.85 1st: To Hell And Back 1:10.18 22.4L
AVON 21 Dec 2005 - 1st up 2 of 6 Mdn cg&e $5K 1200 D2.3 Laura Woods [56] 57
(4) 6/6 $18.15 1st: Sol Invictus 1:12.27 .4L
Tidy run when second resuming. Draw a concern.

2 03x93. Jaca Rema (14) 4g b
 
Z

zkid

Maybe I didn't see it, but you didn't state what exactly is going wrong.
However, I do see the following problems in your code:

1. Try changing all of your .Wrap = wdFindContinue to .Wrap = wdFindStop.

wdFindContinue will cause the code to keep looping over and over and over....

2. You should always test to verify that the item was actually found. For
example,

Just after the Selection.Find.Execute line, use the following:
If Selection.Find.Found = True then
the rest of your code here
End if

You don't want the code executing if the search text wasn't found.

zkid

Steved said:
Hello from Steved

The macro below does this

Find Prz, then Find F, turn on Extension and find .Size = 30 and .Bold =
True,
move up 2 while in extension and then delete.

Ok the issue is Do While .Execute

I have used the step through ( F8) and it works fine for the first but
second one I have a problem with Do While .Execute, Please where do I need to
place it so that it starts at the beginning each time please. I have posted
under the macro What I mean. Each starts with a number ie 1, 2 etc Thankyou.

Sub Test()
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Prz"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
With Selection.Find
.Text = "F"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find.Font
.Size = 30
.Bold = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True

Do While .Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Loop
End With
End Sub

1 x80x2 Invigorate (17) 4g blk
Colombia-Flight Hero (by Clay Hero) [Legally Blonde 5m(Magic Of Sydney)]
Laura Woods 57kg (R57)
Royal blue, white stars, red sleeves, emerald green armbands & cap
Stats:
Trainer: Peter Lock (Te Rapa)
Owner: Messrs G T Grant & P W Lock
All 4:0:1:0:0
Prz $1,000
F 0:0:0
G 1:0:0
D 1:0:1
S 1:0:0
H 1:0:0
C 0:0:0
Dst 0:0:0 F90 3:0:1:0
2Up 1:0:0:0
Fav 0:0:0:0
2 Fav 1:0:0:0
Win $0.00
Plc $0.66
Perf: STRA 31 Dec 2004 - 1st up 9 of 11 F-Mdn $6K 1200 S4.1 Hayden Tinsley
[53.5] 55 (7) 2/1 $4.50 1st: Monsanto 1:14.31 9.2L
DARG 11 May 2005 - 1st up 8 of 12 Mdn $6K 1200 G- Cameron Lammas [54.5] 56
(11) 6/5 $10.50 1st: Cheerful Star 1:11.99 5.4L
TAWA 01 Jun 2005 21 dys 2nd up 12 of 12 Mdn cg&e $5K 1150 H4.7 Lisa Cropp
[56] 56 (12) 7/7 $11.85 1st: To Hell And Back 1:10.18 22.4L
AVON 21 Dec 2005 - 1st up 2 of 6 Mdn cg&e $5K 1200 D2.3 Laura Woods [56] 57
(4) 6/6 $18.15 1st: Sol Invictus 1:12.27 .4L
Tidy run when second resuming. Draw a concern.

2 03x93. Jaca Rema (14) 4g b
 
S

Steved

Hello zkid

thankyou for your explanation as to what i need to look for.

Cheers.

zkid said:
Maybe I didn't see it, but you didn't state what exactly is going wrong.
However, I do see the following problems in your code:

1. Try changing all of your .Wrap = wdFindContinue to .Wrap = wdFindStop.

wdFindContinue will cause the code to keep looping over and over and over....

2. You should always test to verify that the item was actually found. For
example,

Just after the Selection.Find.Execute line, use the following:
If Selection.Find.Found = True then
the rest of your code here
End if

You don't want the code executing if the search text wasn't found.

zkid

Steved said:
Hello from Steved

The macro below does this

Find Prz, then Find F, turn on Extension and find .Size = 30 and .Bold =
True,
move up 2 while in extension and then delete.

Ok the issue is Do While .Execute

I have used the step through ( F8) and it works fine for the first but
second one I have a problem with Do While .Execute, Please where do I need to
place it so that it starts at the beginning each time please. I have posted
under the macro What I mean. Each starts with a number ie 1, 2 etc Thankyou.

Sub Test()
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Prz"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
With Selection.Find
.Text = "F"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find.Font
.Size = 30
.Bold = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True

Do While .Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Loop
End With
End Sub

1 x80x2 Invigorate (17) 4g blk
Colombia-Flight Hero (by Clay Hero) [Legally Blonde 5m(Magic Of Sydney)]
Laura Woods 57kg (R57)
Royal blue, white stars, red sleeves, emerald green armbands & cap
Stats:
Trainer: Peter Lock (Te Rapa)
Owner: Messrs G T Grant & P W Lock
All 4:0:1:0:0
Prz $1,000
F 0:0:0
G 1:0:0
D 1:0:1
S 1:0:0
H 1:0:0
C 0:0:0
Dst 0:0:0 F90 3:0:1:0
2Up 1:0:0:0
Fav 0:0:0:0
2 Fav 1:0:0:0
Win $0.00
Plc $0.66
Perf: STRA 31 Dec 2004 - 1st up 9 of 11 F-Mdn $6K 1200 S4.1 Hayden Tinsley
[53.5] 55 (7) 2/1 $4.50 1st: Monsanto 1:14.31 9.2L
DARG 11 May 2005 - 1st up 8 of 12 Mdn $6K 1200 G- Cameron Lammas [54.5] 56
(11) 6/5 $10.50 1st: Cheerful Star 1:11.99 5.4L
TAWA 01 Jun 2005 21 dys 2nd up 12 of 12 Mdn cg&e $5K 1150 H4.7 Lisa Cropp
[56] 56 (12) 7/7 $11.85 1st: To Hell And Back 1:10.18 22.4L
AVON 21 Dec 2005 - 1st up 2 of 6 Mdn cg&e $5K 1200 D2.3 Laura Woods [56] 57
(4) 6/6 $18.15 1st: Sol Invictus 1:12.27 .4L
Tidy run when second resuming. Draw a concern.

2 03x93. Jaca Rema (14) 4g b
 

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