Consulting

Results 1 to 6 of 6

Thread: Find and Replace Numbers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Question Find and Replace Numbers

    Hi all,

    I'm trying to create a macro that will replace numerical values in only yellow highlighted texts to 'x' and then highlights to black.
    At the moment my code works for all highlighted texts not just yellow.
    The first part of the code is really the issue as the code only looks for numerical characters in any highlighted text. How can I change this to make it only identify yellow highlighted texts?
    And can anyone suggest how this whole code (part one and two) can be more efficient?

    Any help would be appreciated!
    Sub NbrChange()
    
    Application.ScreenUpdating = False
    
    Lookfor = "1234567890"
    Dim i As Long
    For i = 1 To Len(Lookfor)
      Lookchar = Mid$(Lookfor, i, 1)
      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
        .Text = Lookchar
        .Replacement.Text = "x"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchAllWordForms = False
        .Highlight = True
        
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
    Next
    Dim r As Range
    Set r = ActiveDocument.Range
    With r.Find
      .Highlight = True
      Do While .Execute
        If r.HighlightColorIndex = 7 Then
          r.HighlightColorIndex = 1
        End If
      Loop
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by YengKW; 09-20-2018 at 12:53 AM. Reason: Added code tags & formatting

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •