2

I tried to replace this '.' '@' '?' to string BAD Character in Column 'D' with Highlighted in color Red, but i am missing something in this, some one please assist.
Thanks.

Sub Finding()
    Cells.Select
    Selection.Replace What:=".", Replacement:="BAD Character", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Range("D2").Select
End Sub
Community
  • 1
  • 1

1 Answers1

1

Your code works. You can use the below code to loop thru bad characters.

Sub Finding()

    Dim badChar As String, str_bad As String
    badChar = ".@"

    For i = 1 To Len(badChar)
        str_bad = Mid(badChar, i, 1)
        Columns(4).Replace What:=str_bad, Replacement:="BAD Character", LookAt:=xlPart, _
                           SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

    Next
End Sub

enter image description here

Getting wildcards to work in find and replace function in VBA macro

Community
  • 1
  • 1
Santosh
  • 12,175
  • 4
  • 41
  • 72