I have built a small macro that is not working properly. I want the macro to replace any occurance of the word "Go" with an automatically generated number with an associated word "LineNumber: " When the macro is run, the first replacement action is off. Then, if the number of replacements to be made is less than the loop count in the macro, the loop keeps running making the end of the running not correct.
I need to eliminate the specific number in the loop counter and make the macro stop running after all of the available replacements have been made no matter how few or how many replacements are on the page.
QUOTE
Go
Gt
Go
Gt
Go
Gt
Go
Gt
Go
Gt
Go
Gt
Go
Gt
Result Produced By Macro
QUOTE
LineNumber: 1LineNumber: 2
Gp
Gp
LineNumber: 3
Gp
Gp
LineNumber: 4
Gp
Gp
LineNumber: 5
Gp
Gp
LineNumber: 6
Gp
Gp
LineNumber: 7
Gp
Gp
LineNumber: 8LineNumber: 9LineNumber: 10
Gp
Gp
Result Wanted By Macro
QUOTE
LineNumber: 1
Gp
Gp
LineNumber: 2
Gp
Gp
LineNumber: 3
Gp
Gp
LineNumber: 4
Gp
Gp
LineNumber: 5
Gp
Gp
LineNumber: 6
Gp
Gp
LineNumber: 7
Gp
Gp
LineNumber: 8
Gp
Gp
This page contains 14 replacements
QUOTE
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Result Produced By Macro
QUOTE
LineNumber: 1LineNumber: 2
Gp
Gp
LineNumber: 3
Gp
Gp
LineNumber: 4
Gp
Gp
LineNumber: 5
Gp
Gp
LineNumber: 6
Gp
Gp
LineNumber: 7
Gp
Gp
LineNumber: 8
Gp
Gp
LineNumber: 9
Gp
Gp
LineNumber: 10
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Go
Gp
Gp
Result Wanted By Macro
QUOTE
LineNumber: 1
Gp
Gp
LineNumber: 2
Gp
Gp
LineNumber: 3
Gp
Gp
LineNumber: 4
Gp
Gp
LineNumber: 5
Gp
Gp
LineNumber: 6
Gp
Gp
LineNumber: 7
Gp
Gp
LineNumber: 8
Gp
Gp
LineNumber: 9
Gp
Gp
LineNumber: 10
Gp
Gp
LineNumber: 11
Gp
Gp
LineNumber: 12
Gp
Gp
LineNumber: 13
Gp
Gp
LineNumber: 14
Gp
Gp
Here is the macro needing changes
CODE
Sub DoLoopDemo()
'
' DoLoopDemo Macro
' Macro created 7/3/2008
'
'Loop: Do...Loop Demo:
'Selection.TypeText Text:="LineNumber: "
'Selection.TypeText Text:=intCounter
Do While intCounter < 10
intCounter = intCounter + 1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Go"
.Replacement.Text = intCounter
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Selection.TypeText Text:="LineNumber: "
CycleCount = CycleCount + 1
Selection.TypeText Text:=CycleCount
End With
Selection.Find.Execute
Loop
End Sub
Thank you in advance for any replies.