Hello members, I am using the code below posted below to find and replace within range that I have assigned to selection.range but the problem here is it not only replacing within range but beyond the range.
Code:
Sub nnewreplace()
Dim e(), f()
e = Array(" ", " ", Chr(160), Chr(9), "\(([a-z]{1,})\)")
f = Array("", "", "", "", "\1.")
Dim i As Integer
Dim rng As Range
Set rng = Selection.Range
For i = LBound(e) To UBound(e)
With rng.find
.ClearFormatting
.MatchWildcards = True
.Text = e(i)
.Replacement.Text = f(i)
.Wrap = wdFindStop
End With
rng.find.Execute Replace:=wdReplaceAll
Next
End Sub
Here all replaced are within range except the last one. I looked by stepping through the code and I found that up to the second last item of the array e(i) the rng was the selection.range but when it passes rng.find.Execute Replace:=wdReplaceAll of last item the rng becomes "" . What can be done to avoid that problem? Any reply would be of great help.