Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-22-2022, 04:15 AM
Bikram Bikram is offline replacing_within_range Windows 10 replacing_within_range Office 2007
Advanced Beginner
replacing_within_range
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default replacing_within_range


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.

Last edited by Bikram; 04-22-2022 at 04:24 AM. Reason: Added additional details
Reply With Quote
 

Thread Tools
Display Modes


Other Forums: Access Forums

All times are GMT -7. The time now is 01:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft