Excel VBA
Excel VBA查找变色
2017-04-28 17:40:44

从C1:D10中查找同行第m列中的字符(n为连续字符数),把相同字符变成红色

Sub CGC()

    Dim i As Long

    Dim tmpRange As Range

    Dim strS As String

    For Each tmpRange In Range([c1], [d10])

        strS = tmpRange.Text

        For i = 1 To Len(strS)

            If Cells(tmpRange.Row, m).Text Like "*" & Mid$(strS, i, n) & "*" Then

                With tmpRange.Characters(Start:=i, Length:=1).Font

                    .ColorIndex = 3

                End With

            End If

        Next

    Next

End Sub