我想要使用条件格式的正确代码。我有第 4 季度销售表总和的数据(“K8:K207”)。我想在有 3 个条件的情况下应用条件格式:
- 将大于 1,00,000 的年份的 K 列(年度销售总额)突出显示为绿色
- 90,000 至 1,00,000 之间为琥珀色
- 小于 90,000 为红色
请帮助我如何使用循环编写代码。
你不需要为此循环。您只需将新的 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)