Excel) (ColorScale 对象
代表色阶条件格式规则。
备注
所有条件格式设置对象都包含在 FormatConditions 集合对象中,该对象是 Range 集合的子对象。 可以使用 FormatConditions 集合的 Add 或 AddColorScale 方法创建色阶格式规则。
色阶是直观的参照,可以帮助您了解数据的分布和变化。 您可以对数据范围、表中的数据或数据透视表中的数据应用双色或三色色阶。 对于双色色阶条件格式,您可以将值、类型和颜色分配给范围的最小和最大阈值。 三色色阶还具有中点阈值。
每个阈值都是通过设置 ColorScaleCriteria 对象的属性来确定的。 ColorScaleCriteria 对象是 ColorScale 对象的子项,也是色阶的所有 ColorScaleCriterion 对象的集合。
示例
以下代码示例创建了一个数字范围,然后将双色色阶条件格式规则应用于该范围。 然后指定最小阈值的颜色为红色,最大阈值的颜色为蓝色。
Sub CreateColorScaleCF()
Dim cfColorScale As ColorScale
'Fill cells with sample data from 1 to 10
With ActiveSheet
.Range("C1") = 1
.Range("C2") = 2
.Range("C1:C2").AutoFill Destination:=Range("C1:C10")
End With
Range("C1:C10").Select
'Create a two-color ColorScale object for the created sample data range
Set cfColorScale = Selection.FormatConditions.AddColorScale(ColorScaleType:=2)
'Set the minimum threshold to red and maximum threshold to blue
cfColorScale.ColorScaleCriteria(1).FormatColor.Color = RGB(255, 0, 0)
cfColorScale.ColorScaleCriteria(2).FormatColor.Color = RGB(0, 0, 255)
End Sub
方法
属性
- 应用程序
- AppliesTo
- ColorScaleCriteria
- Creator
- Formula
- Parent
- Priority
- PTCondition
- ScopeType
- StopIfTrue
- Type
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。