I have an established range in a table. In that range there is verbiage
surrounded by parenthesis like (abc) (defghi) (jklm) etc. I would like to
select each instance in the range to do something with it before going to the
next row.
Can anyone help with this.
Sub GetVerbiage()
Dim totCount As Integer, i As Integer, myVerbiage As String,
rngToSearch As Range, rngResult As Range, intRow As Integer
totCount = ActiveDocument.Tables(23).Rows.Count
For i = 14 To totCount
Set rngToSearch =
ActiveDocument.Tables(23).Rows(i).Cells(7).Range
Set rngResult = rngToSearch.Duplicate
With rngResult.Find
.ClearFormatting
.Text = "\(*\)"
.Forward = True
.MatchWildcards = True
.Wrap = wdFindContinue
.Execute
End With
If rngResult.Find.Found Then
'do something here
End If
'At this point there is other verbiage in the range that I
would like to look at and maybe do something with it but the code jumps
to the next i. How do I get it to look at the next instance where there is
verbiage surronded by parenthesis like (Now is the time1) (Now is the time2)'
Next i
End Sub
Replace these lines
.Execute
End With
If rngResult.Find.Found Then
'do something here
End If
with these lines
Do While .Execute And rngResult.InRange(rngToSearch)
'do something here
Loop
End With
The .Execute method returns a boolean result that is always exactly the same
as the value of rngResult.Find.Found. A side effect of the .Execute is that
rngResult is redefined to cover only the found text. The InRange method
checks that the found text is within rngToSearch, so the loop stops after
processing the last occurrence within the search range.
If the processing that occurs inside the loop changes the size or contents
of rngResult, then the last statement before the Loop line must set
rngResult to the end of its original location, so the next iteration starts
searching from that point. Failure to do this can result in an infinite loop
if it causes the search to find the same location again. If all you're doing
is reformatting or copying the range, this step isn't necessary.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
> I have an established range in a table. In that range there is
> verbiage surrounded by parenthesis like (abc) (defghi) (jklm) etc. I
[quoted text clipped - 34 lines]
> Next i
> End Sub
dejones923 - 20 Sep 2007 20:20 GMT
Thank's Jay, this was "right on point" and resolved my issue.

Signature
Thank you
DJ
> Replace these lines
>
[quoted text clipped - 63 lines]
> > Next i
> > End Sub