Function COLORFUNCTION(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
COLORFUNCTION = vResult
End Function
count :=ColorFunction(H1,I4:I9
sum:=ColorFunction(H1,I4:I9,1)
H1:ô chứa màu cần đếm
I4:I9:răng cần đếm bao nhiêu ô chứa màu H1
Nhận xét
Đăng nhận xét