1

나는 VBA 세계에 매우 새롭고 조건부 서식의 VBA 측면에 대한 도움이 필요합니다.조건부 서식 VBA 여러 조건

1) I 조건부 서식 필요가 함께 7-20

  • 적색보다 20
  • 에서

    • 녹색
    • 옐로우 7에서 (M) 컬럼에 적용 할 조건을 재정의하면 column (N)에 NOPO가 표시되면 조건부 서식을 적용하지 않아도됩니다.

      는 그게 필요하지만 (조건부 서식을 적용 할 경우,이 공식은 무슨 색깔을 보여줍니다.

      =IF(N2="osno",IF(M2<=7,"green",IF(M2<7,IF(M2>20,"red","less than 20"),IF(M2>20,IF(M2>20,"red","less than 20"),"yellow"))),"no format") 
      

      이를 VBA 조건부 서식으로 그 회전 할 수없는 어떤 색상 표시 사용하는 수식을 일했다 당신은 의심의 여지가 매우 지저분한의 볼과 기록 스크립트에서였다 수있는 내 현재 VBA 스크립트이다.

      Sub Conditional() 
      ' 
      ' Notification_05 Macro 
      ' Conditional Formatting 
      ' 
      
      ' 
          Sheets("Final").Select 
          Columns("M:M").Select 
      
          Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _ 
           Formula1:="=8" 
          Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
          With Selection.FormatConditions(1).Interior 
           .PatternColorIndex = xlAutomatic 
           .Color = 5296274 
           .TintAndShade = 0 
          End With 
          Selection.FormatConditions(1).StopIfTrue = False 
          Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _ 
           Formula1:="=8", Formula2:="=20" 
          Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
          With Selection.FormatConditions(1).Interior 
           .PatternColorIndex = xlAutomatic 
           .Color = 49407 
           .TintAndShade = 0 
          End With 
          Selection.FormatConditions(1).StopIfTrue = False 
          Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _ 
           Formula1:="=20" 
          Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority 
          With Selection.FormatConditions(1).Interior 
           .PatternColorIndex = xlAutomatic 
           .Color = 470000 
           .TintAndShade = 0 
          ActiveWindow.SmallScroll Down:=-27 
          Range("M2").Select 
          With Range("M:M") 
           .FormatConditions.Add Type:=xlExpression, Formula1:= _ 
            "=LEN(TRIM(M1))=0" 
           With .FormatConditions(.FormatConditions.Count) 
            .SetFirstPriority 
             End With 
              End With 
              End With 
      End Sub 
      

      감사합니다,

      쏴 ke

    +0

    을'= IF (N2 = "osno"IF (M2 (20) <(M2 <7,IF(M2> 20 IF, "적색", "20 미만") IF (M2 = 7 "녹색"> , IF (M2> 20, "red", "20 미만", "yellow"))), "no format")'= IF (N2 = "osno", IF (M2 <= 7) 'M2 <7' 부분은 항상'False'로 평가되고 두 ​​번째'M2> 20'은 "녹색", IF (M2> 20, "빨간색", "노란색")) 첫 번째 'M2> 20'을 지나면 항상 '참'이됩니다. 그게 당신이 VBA 코드로 작성하는 데 도움이되지 않지만, 당신이해야 할 일을 간소화 할 수 있습니다. – YowE3K

    답변

    0

    CF 공식은 true 또는 false를 반환해야합니다. 하나의 수식을 사용하여 여러 색상 중 하나를 할당하고 색상 적용 여부를 결정할 수 없습니다. 약간 다른 공식을 가진 세 가지 규칙이 필요합니다.

    Sub Tester() 
    
        Dim rng As Range 
    
        Set rng = Selection 
    
        rng.FormatConditions.Delete 'clear any existing rules 
    
        AddRule rng, "=AND(M2=""osno"", N2<7)", vbGreen 
        AddRule rng, "=AND(M2=""osno"", N2>=7,N2<=20)", vbYellow 
        AddRule rng, "=AND(M2=""osno"", N2>20)", vbRed 
    
    End Sub 
    
    'utility sub: add a CF rule given the formula and a fill color 
    Sub AddRule(rng, sFormula, lColor) 
        With Selection.FormatConditions 
         With .Add(Type:=xlExpression, Formula1:=sFormula) 
          .Interior.Color = lColor 
          .StopIfTrue = True 
         End With 
        End With 
    End Sub