我想自定义图标标准。我需要5个条件。我使用了 IconSetCondition。
条件是:
- 值 < 0.85
- 值 < 0.95
- 值<1.06
- 值<1.15
- 值 >=1.15
我想以这种方式使用3个交通灯:
- 值 < 0.85 -->“红色交通灯”
- 值<0.95 -->“橙色交通灯”
- 值<1.06 -->“绿色交通灯”
- 值<1.15 -->“橙色交通灯”
- 值 >=1.15 --> “红色交通灯”
我自愿使用 xl5Arrows 来获得 5 个条件。
Set r = Range(Cells(3, 6), Cells(nbtopics + 2, 6))
With r
With .FormatConditions
.Delete
.AddIconSetCondition
End With
With .FormatConditions(1)
.SetFirstPriority
.ReverseOrder = False
.ShowIconOnly = False
.IconSet = ActiveWorkbook.IconSets(xl5Arrows)
With .IconCriteria(2)
.Type = xlConditionValueNumber
.Value = 0.85
.Operator = xlGreater
End With
With .IconCriteria(3)
.Type = xlConditionValueNumber
.Value = 0.95
.Operator = xlGreater
End With
With .IconCriteria(4)
.Type = xlConditionValueNumber
.Value = 1.05
.Operator = xlGreater
End With
With .IconCriteria(5)
.Type = xlConditionValueNumber
.Value = 1.15
.Operator = xlGreater
End With
End With
End With
此代码有效,但我想要交通灯
而不是xl5Arrows
。
非常感谢您的帮助。如果您需要更多详细信息,请随时发表评论。
最佳答案
如Mark S. mentioned , xlIconSet
enum 中没有默认的 xl5trafficlights
但是,您当前正在设置 IconCriteria 的 .Type
、.Value
和 .Operator
- 只需确保还要同时设置.Icon
。这会将 IconSetCriteria
设置为 xlCustomSet
。
这是一个xlIcon
- “圆圈”,供您构建 5 个交通灯组,如下所示:
xlIconBlackCircleWithBorder
xlIconGrayCircle
xlIconGreenCircle
xlIconRedCircleWithBorder
xlIconPinkCircle
xlIconYellowCircle
xlIconGreenCheckSymbol
xlIconRedCrossSymbol
xlIconYellowExclamationSymbol
xlIconWhiteCircleAllWhiteQuarters
例如
With .IconCriteria(1)
.Icon = xlIconWhiteCircleAllWhiteQuarters
End With
With .IconCriteria(2)
.Icon = xlIconGreenCircle
.Type = xlConditionValueNumber
.Value = 0.85
.Operator = xlGreater
End With
With .IconCriteria(3)
.Icon = xlIconYellowCircle
.Type = xlConditionValueNumber
.Value = 0.95
.Operator = xlGreater
End With
With .IconCriteria(4)
.Icon = xlIconRedCircleWithBorder
.Type = xlConditionValueNumber
.Value = 1.05
.Operator = xlGreater
End With
With .IconCriteria(5)
.Icon = xlIconBlackCircleWithBorder
.Type = xlConditionValueNumber
.Value = 1.15
.Operator = xlGreater
End With
关于excel - 如何根据条件自定义图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57182771/