55
ColorScale Object Example
This example adds a three-color scale formatting rule to a specified range:
Sub CreateColorScale()
Dim oColorScale As ColorScale
‘Add a three-color scale
Set oColorScale = Range(“F6:F16”).FormatConditions.AddColorScale(ColorScaleType:=3)
‘Set the minimum threshold to the lowest value in the range
‘Set the color for the minimum threshold
oColorScale.ColorScaleCriteria(1).Type = xlConditionValueLowestValue
oColorScale.ColorScaleCriteria(1).FormatColor.Color = 7039480
‘Set the midpoint threshold to the value in a specific cell (cell F10 in this case)
‘Set the for the midpoint threshold
oColorScale.ColorScaleCriteria(2).Type = xlConditionValueNumber
oColorScale.ColorScaleCriteria(2).Value = “=$F$10”
oColorScale.ColorScaleCriteria(2).FormatColor.Color = 49407
‘Set the maximum threshold to the lowest value in the range
‘Set the color for the maximum threshold
oColorScale.ColorScaleCriteria(3).Type = xlConditionValueHighestValue
oColorScale.ColorScaleCriteria(3).FormatColor.Color = 8109667
End SubColorScaleCriterion and the
ColorScaleCriteria Collection
The ColorScaleCriteriacollection holds each ColorScaleCriterionin a color scale conditional
format. Each criterion specifies the minimum, midpoint, or maximum threshold for the color scale.
ColorScaleCriteria Common Properties
The Countand Itemproperties are defined at the beginning of this appendix.
ColorScaleCriterion Properties
Name
Returns
Description
FormatColor
Format
Returns a FormatColorobject, which defines the color
Color
assigned to the specified color scale threshold. Read-only
Index
Long
Returns a value that represents the threshold for
the criteria. For two-color scales, the index values will be
1 for the minimum threshold and 2 for the maximum
threshold. For three-color scales, the values will be 1 for
the minimum threshold, 2 for the midpoint, and 3 for the
maximum. Read-only
Type
xlCondition
Specifies how the threshold values for a color scale
ValueTypes
conditional format are determined (number, percent, for-
mula, or percentile). This property will return an xlCon-
ditionValueTypesconstant
Value
Variant
Set/Get the value for the minimum, midpoint, and maxi-
mum thresholds in a color scale conditional formatting rule
713
ColorScale Object Example