본문 바로가기
카테고리 없음

[vba] 조건부 서식이 걸린 셀 Display 색상 가져오기

by IT HUB 2020. 9. 8.
728x90
반응형

조건부 서식이 걸린 셀의 색상을 카운트할 수 있습니다.

아래처럼 [알고자 하는 셀].DisplayFormat.Interior.Color로 조건부 서식으로 지정한 셀 색상 값을 가져올 수 있습니다.

dColor = rasCell.DisplayFormat.Interior.Color

 

Function Color(intRng As Range) As String
    Dim rasCell As Range
    Dim Y As Integer
    Dim R As Integer
    Dim G As Integer
    Dim dColor As Long
    For Each rasCell In intRng
        If rasCell.FormatConditions.Count > 0 Then
            dColor = rasCell.DisplayFormat.Interior.Color
            If dColor = RGB(2552550Then
                Y = Y + 1
            ElseIf dColor = RGB(25500Then
                R = R + 1
            ElseIf dColor = RGB(8413053Then
                G = G + 1
            End If
        End If
    Next
    Color = Y & R & G
End Function
 
 

 

반응형


댓글