PDA

View Full Version : [SOLVED:] Iterate through one loop while in another



charliew001
10-07-2013, 11:29 AM
The below code is to format all spacing in a document to have two spaces after a sentence ending with a period. I am having trouble trying to get ucaseletter(z) iterate itself while lcaseletter(i) is iterating. Essentially, for every character in lcaseletter(i), I want it to do a search and replace with every character of ucaseletter(z). So, the loop would start with (a.), and loop through every character in ucaseletter(z) to get every combination of (a.) and ucaseletter(z). Also, I'm doing this with a track changed document, hence I can't use wildcards.


For i = 0 To 25
uCaseletter(i) = Chr$(65 + i)
lCaseletter(i) = Chr$(97 + i)
Next


For i = 0 To 25
With Selection.find
.Text = lCaseletter(i) & ". " & uCaseletter(z)
.Replacement.Text = lCaseletter(i) & ". " & uCaseletter(z)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.find.Execute replace:=wdReplaceAll
Next

charliew001
10-07-2013, 03:29 PM
Solved. Changed my loop to a do until.


Do
With Selection.find
.Text = lCaseletter(i) & ". " & uCaseletter(z)
.Replacement.Text = lCaseletter(i) & ". " & uCaseletter(z)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.find.Execute replace:=wdReplaceAll
i = i + 1
If i = 26 Then
z = z + 1
i = 0
End If
Loop Until z = 26