엑셀에서 같은 색이 칠해진 셀의 합계 구하기

Public Function SumByBGColor(TargetRange, Optional RefCell) As Variant
    SumByBGColor = 0
    If IsMissing(ColorCell) Then
        SumColorIndex = Application.Caller.Interior.ColorIndex
    Else
        SumColorIndex = RefCell.Interior.ColorIndex
    End If
    For Each x In TargetRange
        If x.Interior.ColorIndex = SumColorIndex Then
            SumByBGColor = SumByBGColor + x.Value
        End If
    Next
End Function

TargetRange에서 RefCell과 같은 색으로 칠해진 셀끼리 합을 구하는 함수. 생각한대로 동작하긴 하는데, 에러체크를 뭘 해야 하는지도 잘 모르겠고, 버그가 뭐가 있는지도 잘 모르겠다. 일단은 TargetRange에 포함된 셀의 값이 변하면 재계산이 자동으로 되는데 배경색이 변하면 자동으로 안된다.

관련 내용을 찾아보다 발견한 사이트: Pearson Software Consulting

,