Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 move to next iteration..I have tried the following code.

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

However during the execution I am getting runtime error 424 "Object Required.Please help me to complete this task

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...