본문 바로가기

VBA/Code

[VBA] ColorSum

반응형

Basic 파일 다운로드

ColorSum.bas
0.00MB

함수 사용방법

VBA Code

Function ColorSum(sumRange As range, colorRange As range, Optional colorType As Boolean = False) As Double
    Application.Volatile True
    On Error Resume Next
    Dim rng As range, result As Double
    If colorType Then
        For Each rng In sumRange
            If rng.Font.ColorIndex = colorRange.Font.ColorIndex Then result = result + rng.Value
        Next rng
    Else
        For Each rng In sumRange
            If rng.Interior.ColorIndex = colorRange.Interior.ColorIndex Then result = result + rng.Value
        Next rng
    End If
    ColorSum = result
End Function

 

유사 함수

반응형