2012-01-25 14 views
5

条件付き書式を使用するための適切なコードが必要です。私は4四半期の売上高( "K8:K207")の合計のデータを持っています。 VBAを使用する条件付き書式

  • アンバーとして1,00,000に90,000の間
  • グリーンとして1,00,000よりも大きい年

    1. ハイライト列K(年間総販売):私は3つの条件を持っている条件付き書式を適用したいです赤としては90,000以下

    ループを使用してコードを書く方法を教えてください。

    答えて

    10

    このためにループは必要ありません。範囲オブジェクトに新しいFormatConditionを追加するだけで済みます。

    lLow = 90000 
    lHigh = 100000 
    
    Set rng = Range("K8:K207") 
    rng.FormatConditions.Delete ' delete any pre-existing formatting 
    
    ' add greater than condition 
    With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlGreater, Formula1:="=" & lHigh) 
        .Interior.Color = rgbLimeGreen 
    End With 
    
    ' add middle condition 
    With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlBetween, Formula1:="=" & lLow, Formula2:="=" & lHigh) 
        .Interior.Color = rgbGold 
    End With 
    
    ' add less than condition 
    With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlLess, Formula1:="=" & lLow) 
        .Interior.Color = rgbRed 
    End With 
    
    関連する問題