2016-07-04 18 views
0

歪曲的問題,但我正在做一些基於間隔的條件格式化,以解決硬編碼條件格式,因爲前者總是優先於後者。本質上,硬編碼標題之間的顏色代碼,但在某些情況下,我只在硬編碼顏色之間有一行,因此三個比例的條件格式將默認突出顯示綠色的負數;我如何強迫VBA強調紅色的負面?VBA中是否有方法指定條件格式的縮放比例,以便負數用紅色編碼?

End With 
With Range(Replace(range_, "#", "N")).FormatConditions.AddColorScale(3) 
End With 

回答

0

基於此Post,我創建了一個方法來修改顏色尺度。

SetColorScale範圍(替換(range_, 「#」, 「N」))

Sub SetColorScale(rng As Range) 
    With rng 
     .FormatConditions.AddColorScale ColorScaleType:=2 
     .FormatConditions(.FormatConditions.Count).SetFirstPriority 
     With .FormatConditions(1) 
      With .ColorScaleCriteria(1) 
       .Type = xlConditionValueLowestValue 
       .FormatColor.Color = vbRed 
       .FormatColor.TintAndShade = 0 
      End With 
      With .ColorScaleCriteria(2) 
       .Type = xlConditionValueHighestValue 
       .FormatColor.Color = vbGreen 
       .FormatColor.TintAndShade = 0 
      End With 
     End With 
    End With 

End Sub 
相關問題