I am trying to create a vba countifs function that has mutliple criteria in different columns. I need it to only count the cells in Column E that have an interior color if the corresponding row in column C has a specific text value.
For instance: Only count cell E10 if C10 has value "TL" and E10 has interior color Green
I am using this VBA code to count the number of interior color cells within a range:
Function countif_by_color(rl As Range, r2 As Range) As Long
Application.Volatile
Dim x As Long
Dim cel As Range
x = 0
For Each cel In rl
If cel.Interior.color = r2.Interior.color Then
x = x + 1
End If
Next
countif_by_color = x
End Function
And I have been trying to use it with this formula ( A13 being the color I want it to count):
=(COUNTIFS($C$21:$C$101,"=TL",E21:E101,(countif_by_color(E21:E101,A13))))
But this essentially equates the green cells in column E to a number value which changes the countif criteria to counting cells with that numeric value instead of color.
I want to alter the countif_by_color function VBA to have multiple criteria like a countifs function.... thanks in advance!