VBA 查找字符串的字体颜色

use*_*470 3 vbscript excel vba

我是 VBA 新手。代码。

Dim compare = {"test1","test2","test3",.....etc}

i=0

For j=1 to Ubound(compare)    
  j=1

  If compare.Characters(j,Len(compare(i))).Font.Color <> vbRed Then    
    ' Some Code
  End If

  i=i+1    
Next
Run Code Online (Sandbox Code Playgroud)

但是在执行过程中,我收到运行时错误 424“Object Required. Please help me to complete this task

提前致谢。

Gar*_*ent 5

假设我们有单元格A1A4,例如:

图片

然后这段代码会找到非红色字符:

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
Run Code Online (Sandbox Code Playgroud)