View Single Post
 
Old 10-31-2023, 02:41 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default Replace with zero any digit string of any length containing the letter O

I am trying to work out a macro that replaces the letter O with zero ('0') in any position within a digit string. I cannot go any further into the tentative code here below. Thanks!
Code:
Sub LetterToZero()
'Replace with zero any digit string of any length containing the letter O
'Test sequence: This sequence 145O or this 4O56 or this O4578
    Set aRng = ActiveDocument.StoryRanges(wdMainTextStory)
    With aRng.Find
      .ClearFormatting
      .Text = "O[0-9]"
'      .Text = "[0-9]O"
'       find letter O inside digit string
'      .Replacement.Text = "0" 'Replace only the letter O
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWildcards = True
      .Execute
'If .Found = True Then MsgBox "Found " & aRng.Text
    End With
End Sub
Reply With Quote