본문 바로가기

VBA/Code

[VBA] ColorAverage

반응형

Basic 파일 다운로드

ColorAverage.bas
0.00MB

 

함수 사용방법

VBA Code

 

Function ColorAverage(AverageRange 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, cnt As Long
    If colorType Then
        For Each rng In AverageRange
            If rng.Font.ColorIndex = colorRange.Font.ColorIndex Then result = result + rng.Value: cnt = cnt + 1
        Next rng
    Else
        For Each rng In AverageRange
            If rng.Interior.ColorIndex = colorRange.Interior.ColorIndex Then result = result + rng.Value: cnt = cnt + 1
        Next rng
    End If
    ColorAverage = result / cnt
End Function

 

유사 함수

반응형