【问题标题】:Format Top 3 and Bottom 3 Values for each row格式化每行的前 3 和后 3 值
【发布时间】:2013-09-11 19:52:57
【问题描述】:

我想我可能需要一个 VBA 宏来解决这个问题。我有一个大约 10,000 行的数据集,包含 15 列值,我想要做的是,对于每一行,通过条件格式设置前三个值和后三个值来突出显示。

我已经使用 xl2010 中的条件格式化工具为第 1 行设置了规则,但是当我在剩余的 9,999 行上复制粘贴特殊格式时,结果是只格式化前三个和后三个值包含在 9,999 行中。

我希望看到每行前 3 和后 3 的阴影,而不是整个数据集,最好不要复制粘贴特殊 9,999 次!

【问题讨论】:

    标签: excel excel-2010 conditional-formatting vba


    【解决方案1】:

    宏记录功能非常适合这类问题,尤其是对于初学者(我自己对 VBA 并不那么精通)。

    这将突出显示前 3 个值红色和底部 3 个蓝色值。 注意我的 i 从 1 到 1000,根据需要更改(列部分相同)。

    编辑:更改了您的范围,我第一次没有阅读它们。

    Sub Conditions()
    Dim myrange As Range
    
    
    For i = 1 To 10000
    
    Set myrange = Range("A" & i & ":" & "O" & i)
    myrange.FormatConditions.AddTop10
    myrange.FormatConditions(myrange.FormatConditions.Count).SetFirstPriority
    
    With myrange.FormatConditions(1)
        .TopBottom = xlTop10Top
        .Rank = 3
        .Percent = False
    End With
    With myrange.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    
    myrange.FormatConditions(1).StopIfTrue = False
    myrange.FormatConditions.AddTop10
    myrange.FormatConditions(myrange.FormatConditions.Count).SetFirstPriority
    
    With myrange.FormatConditions(1)
        .TopBottom = xlTop10Bottom
        .Rank = 3
        .Percent = False
    End With
    With myrange.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 15773696
        .TintAndShade = 0
    End With
    
    myrange.FormatConditions(1).StopIfTrue = False
    
    Next
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      • 2012-10-02
      相关资源
      最近更新 更多