1. FAQ
  2. 엑셀(Excel)
  3. AfterEffects
  4. Premiere
  5. Photoshop
  6. ETC

이 게시판은 아별닷컴 회원만 질문을 올릴 수 있습니다. 회원에게 주어지는 특권인셈이지요. 회원이 아닌 분들은 열람만 가능합니다.

[레벨:30]아별

2009.12.31 00:21

안녕하세요?

조건부 서식에서 지정한 셀 색상을 갖고 오고 싶으시군요..

예전에 엑사모 같은데서 비슷한 질문을 본적이 있는데.. 다 못 갖고온다는 답변뿐이었습니다.

 

조건부 서식에서 값으로 조건을 걸었을 경우에는 갖고 올 수가 있는데요..

수식으로 조건을 걸었을때는.. 수식을 어떻게 평가해야할지에 대한 적당한 해법이 없네요..

홀수열에 음영을 넣는 "=MOD(ROW(),2)" 이런 조건이나 조건에 이름을 사용하거나 했을때..

수식으로 조건을 거는 방법은 무궁무진한지라.. 접근이 어렵습니다.

 

 

값으로 조건을 걸었을때 셀색상을 갖고 오는 사용자 정의함수를 만들어봤습니다.

조건부서식이 없거나, 조건을 만족하지 못 할 경우에는 기본 셀 음영색을 갖고 옵니다.

수식으로 된 조건에 해당하면.. "에라"죠.. =_=;;

참고하세요.

 

abyul_20091231_FormatConditions_colorIndex.xls

 

 Option Explicit

Function getConditionalColor(uRange As Range)
    Dim i As Integer
    Dim cntConditions As Integer
    cntConditions = uRange.FormatConditions.Count
    If cntConditions < 1 Then
        getConditionalColor = uRange.Interior.ColorIndex
    Else
        For i = 1 To cntConditions
            With uRange.FormatConditions(i)
                Select Case .Type
                Case xlCellValue
                    Select Case .Operator
                        Case xlBetween
                            If uRange.Value >= .Formula1 And uRange.Value <= .Formula2 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlEqual
                            If uRange.Value = .Formula1 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlGreater
                            If uRange.Value > .Formula1 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlGreaterEqual
                            If uRange.Value > .Formula1 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlLess
                            If uRange.Value < .Formula1 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlLessEqual
                            If uRange.Value <= .Formula1 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlNotBetween
                            If uRange.Value <= .Formula1 Or uRange.Value >= .Formula2 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                        Case xlNotEqual
                            If uRange.Value <> .Formula1 Then
                                getConditionalColor = .Interior.ColorIndex
                                Exit Function
                            End If
                    End Select
                Case xlExpression
                        getConditionalColor = "수식조건평가못함"
                End Select
            End With
        Next i
    End If
    If IsEmpty(getConditionalColor) Then
        getConditionalColor = uRange.Interior.ColorIndex
    End If
End Function


문서 첨부 제한 : 0Byte/ 2.00MB
파일 제한 크기 : 2.00MB (허용 확장자 : *.*)