Forum Discussion

KBmentions's avatar
KBmentions
Copper Contributor
Apr 25, 2022

adding up numbers of colours in a column

Please can someone help.  

 

I have coding which determines a colour in a column dependant on a figure.  I want to add up all the reds in the column and all the greens in the same column. Does anyone know how to do this please?

 

 

2 Replies

  • KBmentions 

    Sub add()
    
    Dim i As Integer
    Dim j As Integer
    
    For i = 3 To 17
    
    If Cells(i, 3).Interior.ColorIndex = 4 Or Cells(i, 3).Interior.ColorIndex = 3 Then
    j = Cells(i, 3).Value + j
    
    Else
    End If
    
    Next i
    
    Cells(1, 1).Value = j
    
    End Sub

    An alternative could be this code. You can click the button in cell F2 in the attached file to start the macro.