I am trying to use a formula that counts a cell colour in one column based on a text value (YES or NO) in a different column. The formula I am using is
=IF(Enrolled_Accommodation="YES",CountByColor(Enrolments!EK$4:EK$1499,83,140,213),0)
The CountByColor is VBA code that works absolutely fine on its own but when combined with the IF statement it reports just the CountByColor value disregarding whether the 'Enrolled_Accommodation' value is YES or not.
The VBA code I am using is:
Public Function CountByColor(rng As Range, Red As Long, Green As Long, Blue As Long) As Long
Dim lCount As Long
Dim rngCell As Range
For Each rngCell In rng
If rngCell.Interior.Color = RGB(Red, Green, Blue) Then
lCount = lCount + 1
End If
Next
CountByColor = lCount
End Function
Is anyone able to tell me what I need to change in either the VBA or formula?
=IF(Enrolled_Accommodation="YES",CountByColor(Enrolments!EK$4:EK$1499,83,140,213),0)
The CountByColor is VBA code that works absolutely fine on its own but when combined with the IF statement it reports just the CountByColor value disregarding whether the 'Enrolled_Accommodation' value is YES or not.
The VBA code I am using is:
Public Function CountByColor(rng As Range, Red As Long, Green As Long, Blue As Long) As Long
Dim lCount As Long
Dim rngCell As Range
For Each rngCell In rng
If rngCell.Interior.Color = RGB(Red, Green, Blue) Then
lCount = lCount + 1
End If
Next
CountByColor = lCount
End Function
Is anyone able to tell me what I need to change in either the VBA or formula?