View Single Post
 
Old 11-02-2021, 04:16 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You don't need to split the found string when it is just one number
Code:
Sub FindTemplate()
  Dim aRng As Range, str As String, int1 As Integer, int2 As Integer, arrStr() As String
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .MatchWildcards = True
    .Text = " [0-9]{2,3}"
    Do While .Execute = True
      int1 = CInt(Trim(aRng.Text)) + 2
      aRng.Text = " " & int1
      aRng.Collapse Direction:=wdCollapseEnd
      aRng.End = ActiveDocument.Range.End
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote