A
Aaron O
I am trying to do a dual find where the first find sets the target
location, and the second find goes in reverse to find the last string
that meets a criterion before the target location. Then I want to
replace parts of the target location with parts of the nearby previous
string. The problem is, when I do the reverse (.forward = false) find
the resulting range is extended from the target location back to the
found string. I need to have two distinct strings to work with, and I
cannot figure out how to turn off this extending behaviour of the
find.
More universally, if anyone knows of a better way to accomplish what I
am trying to do, please let me know.
Thanks! Here's my entire subroutine:
Sub SyncSUB()
Dim SubRng As Range
Dim CommandRng As Range
'Synchronize SUB commands
Set SubRng = Range(0, 0)
With SubRng.Find
.ClearFormatting
.Forward = True
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindStop
.MatchWildcards = True
.Execute FindText:="""SUB*"""
End With
SubRng.Select
Set CommandRng = SubRng
With CommandRng.Find
.ClearFormatting
.Forward = False
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute FindText:="\<COMMAND INDEX=* "
CommandRng.Select
Selection = "" & "SUB" & Mid(CommandRng, 16, Len(CommandRng) -
1) & Right(SubRng, 1) & ""
End With
End Sub
location, and the second find goes in reverse to find the last string
that meets a criterion before the target location. Then I want to
replace parts of the target location with parts of the nearby previous
string. The problem is, when I do the reverse (.forward = false) find
the resulting range is extended from the target location back to the
found string. I need to have two distinct strings to work with, and I
cannot figure out how to turn off this extending behaviour of the
find.
More universally, if anyone knows of a better way to accomplish what I
am trying to do, please let me know.
Thanks! Here's my entire subroutine:
Sub SyncSUB()
Dim SubRng As Range
Dim CommandRng As Range
'Synchronize SUB commands
Set SubRng = Range(0, 0)
With SubRng.Find
.ClearFormatting
.Forward = True
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindStop
.MatchWildcards = True
.Execute FindText:="""SUB*"""
End With
SubRng.Select
Set CommandRng = SubRng
With CommandRng.Find
.ClearFormatting
.Forward = False
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute FindText:="\<COMMAND INDEX=* "
CommandRng.Select
Selection = "" & "SUB" & Mid(CommandRng, 16, Len(CommandRng) -
1) & Right(SubRng, 1) & ""
End With
End Sub