VBA to find the font color of a string

后端 未结 2 1482
执笔经年
执笔经年 2020-12-19 18:18

I am new to VBA..I am writing a macro for some file comparison..My requirement is if a string has red color font,that string should be ignored for iteration and code should

2条回答
  •  醉梦人生
    2020-12-19 19:02

    Say we have cells A1 thru A4 like:

    pic

    Then this code will find the non-red characters:

    Sub ColorTest()
        Dim I As Long, J As Long
        For I = 1 To 4
            For J = 1 To Len(Cells(I, 1).Value)
                If Cells(I, 1).Characters(Start:=J, Length:=1).Font.Color <> vbRed Then
                    MsgBox "non-red found at cell A" & I & " position " & J
                End If
            Next J
        Next I
    End Sub
    

提交回复
热议问题