COUNT cells color with rgb 255,0,0

User avatar
sal21
PlatinumLounger
Posts: 4519
Joined: 26 Apr 2010, 17:36

COUNT cells color with rgb 255,0,0

Post by sal21 »

Ho to count a cells with rgb color 255,0,0 for each row, where column 2 is filled and putt in NOTTI column?

note:

i test with

Code: Select all

Private Sub CONTA_NOTTI()

    Dim I As Integer, T As Integer

    CONTA = 0

    With MSFlexGrid1

        .Redraw = False

        For T = 1 To .Rows - 1

            If .TextMatrix(T, 1) > "" Then

                For I = 3 To 31

                    .Row = T
                    .Col = I

                    If .CellForeColor = RGB(255, 0, 0) Then
                        CONTA = CONTA + 1
                    End If
                    DoEvents

                Next I

                .TextMatrix(T, 34) = CONTA - 1

                CONTA = 1

            End If

        Next T

        .Redraw = True

    End With

End Sub
this dont work why the second and third row have 28 and 28 colored cells for example!
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 79561
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: COUNT cells color with rgb 255,0,0

Post by HansV »

Is this better?

Code: Select all

Private Sub CONTA_NOTTI()
    Dim I As Integer, T As Integer, CONTA As Integer
    With MSFlexGrid1
        .Redraw = False
        For T = 1 To .Rows - 1
            CONTA = 0
            If .TextMatrix(T, 1) > "" Then
                .Row = T
                For I = 3 To 33 ' instead of 31
                    .Col = I
                    If .CellForeColor = vbRed Then
                        CONTA = CONTA + 1
                    End If
                    DoEvents
                Next I
                .TextMatrix(T, 34) = CONTA
            Else
                .TextMatrix(T, 34) = ""
            End If
        Next T
        .Redraw = True
    End With
End Sub
Best wishes,
Hans