代表条件格式规则的前十项。通过对某一区域应用颜色,有助于查看相对于其他单元格的单元格的值。
/p>
说明
所有条件格式对象均包含在 FormatConditions
集合对象中,该集合对象是 Range 集合的子项。您可以使用 FormatConditions
集合的 Add 或 AddTop10 方法创建前 10 个格式规则。
示例
以下示例通过条件格式规则生成一个动态数据集并对前 10 个值应用颜色。
示例代码 |
function Top10CF(){
//Building data
Range("A1").Value2 = "Name"
Range("B1").Value2 = "Number"
Range("A2").Value2 = "Agent1"
Range("A2").AutoFill(Range("A2:A26"), xlFillDefault)
Range("B2:B26").FormulaArray = "=INT(RAND()*101)"
Range("B2:B26").Select()
//Applying Conditional Formatting Top 10
Selection.FormatConditions.AddTop10()
Selection.FormatConditions.Item(Selection.FormatConditions.Count).SetFirstPriority()
let ft = Selection.FormatConditions.Item(1)
ft.TopBottom = xlTop10Top
ft.Rank = 10
ft.Percent = false
//Applying color fill
let rng = Selection.FormatConditions.Item(1).Font
rng.Color = -16752384
rng.TintAndShade = 0
let fpx = Selection.FormatConditions.Item(1).Interior
fpx.PatternColorIndex = xlAutomatic
fpx.Color = 13561798
fpx.TintAndShade = 0
MsgBox("Added Top10 Conditional Format. Press F9 to update values.", jsInformation)
}
|