excel - 如何根据条件自定义图标

标签 excel vba excel-formula

我想自定义图标标准。我需要5个条件。我使用了 IconSetCondition。

条件是:

  1. 值 < 0.85
  2. 值 < 0.95
  3. 值<1.06
  4. 值<1.15
  5. 值 >=1.15

我想以这种方式使用3个交通灯:

  1. 值 < 0.85 -->“红色交通灯”
  2. 值<0.95 -->“橙色交通灯”
  3. 值<1.06 -->“绿色交通灯”
  4. 值<1.15 -->“橙色交通灯”
  5. 值 >=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. mentionedxlIconSet 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/

相关文章:

excel - 从变量命名工作表

ms-access - 使用 VBA 将 RTF 文本从 Access 复制到单词表

excel - 基本 VBA 问题(整数)

Excel 用单元格中的公式排序

excel - 是否可以根据 Excel 中的多个标准(ID、月份和名称)来区分汇总计数?

c# - 使用 C# 从 excel 写入文本文件

vba - 我怎样才能编写产生螺旋的代码?

java - 访问 Excel 文件时出现异常

excel - 使用公式创建下拉列表(无数据验证)

c# - 从另一个工作表中检测依赖单元格