如何复制条件格式而不是扩展它? (格式刷)

问题描述 投票:0回答:1

安装 MS Office 更新后,我无法使用格式刷复制条件格式规则,否则如何在不扩展选择的情况下跨多行复制规则?

用例

我以多种方式使用条件格式,但我的一位最终用户对如何查看数据非常挑剔。假设,他们想要比较每个玩家(作为个人)在游戏中的表现。因此,我会为每个玩家设置 2 条规则,使用色标来显示玩家的表现(命中率和得分)。

上一个流程

为了加快该过程,我将为 Player01 创建它,然后突出显示整行,使用格式刷,并选择 Player02 的行。但是,从 MS Office 版本 16.0.16529.20226 开始,该功能已被破坏,它不是重复后续行的规则,而是扩展条件格式以包括 Player01 和 Player02。 (Player01 游戏 1 FG% 与 Player01 游戏 2 FG% 相比,Player01 游戏 3 FG% 等)

如何在不扩展规则的情况下快速复制每行的规则?

玩家 Game01 命中率% 游戏01积分 Game02 命中率% 游戏02积分 Game03 命中率% 游戏03分 Game04 命中率% 游戏04积分
玩家01 35% 30 37% 13 45% 30 37% 33
玩家02 42% 21 41% 18 39% 23 44% 26
玩家03 18% 9 33% 16 45% 19 36% 7
玩家04 27% 12 25% 8 33% 6 37% 16

包含 Excel 示例图像(FG% 与点的不同规则)

Excel Image

我尝试过的

更新后我已经完成了我能想到的所有故障排除(关闭应用程序,重新启动电脑,在新文件中进行测试)。

每次使用格式刷时,它都会扩展选择以创建 1 条覆盖多行的规则。

奇怪的是 - 如果我应用条件格式的列彼此紧邻(与示例不同),则格式刷将起作用,并将规则从第 1 行复制到第 2 行,而不扩展选择。

挑战之一是我的用户需要如上所述的格式。我不经常使用宏,但我总是在不同数量的游戏和玩家上运行它,而我希望宏需要一致数量的游戏。

excel ms-office conditional-formatting
1个回答
0
投票

Excel(据我所知所有版本)尝试通过使用相同规则合并相邻单元格来简化范围引用。我想唯一的方法是通过 VBA 设置它而不是通过 Excel UI。

Sub Demo()
    Dim oRng As Range, r As Long, c As Long
    Dim pointRng As Range, percentRng As Range
    Call RemoveFC
    Set oRng = ActiveSheet.[a1].CurrentRegion
    Set pointRng = [C1]
    Set percentRng = [B1]
    r = oRng.Cells(1).Row
    For c = 4 To oRng.Columns.Count
        If Int(c / 2) = (c / 2) Then
            ' Get PG% range
            Set percentRng = Application.Union(percentRng, Cells(r, c))
        Else
            ' Get Points range
            Set pointRng = Application.Union(pointRng, Cells(r, c))
        End If
    Next c
    ' Set FormatCondition for each row
    For r = 1 To oRng.Rows.Count - 1
        SetFCondition percentRng.Offset(r, 0)
        SetFCondition pointRng.Offset(r, 0)
    Next r
End Sub
' Set FormatCondition
Sub SetFCondition(oFCRng As Range)
    oFCRng.FormatConditions.AddColorScale ColorScaleType:=3
    With oFCRng.FormatConditions(1)
        .ColorScaleCriteria(1).Type = xlConditionValueLowestValue
        .ColorScaleCriteria(1).FormatColor.Color = 7039480
    End With
    With oFCRng.FormatConditions(1)
        .ColorScaleCriteria(2).Type = xlConditionValuePercentile
        .ColorScaleCriteria(2).FormatColor.Color = 8711167
    End With
    With oFCRng.FormatConditions(1)
        .ColorScaleCriteria(3).Type = xlConditionValueHighestValue
        .ColorScaleCriteria(3).FormatColor.Color = 8109667
    End With
End Sub
' Remove all exist FormatCoditions
Sub RemoveFC()
    Dim r As Range, c
    Set r = ActiveSheet.UsedRange
    For Each c In r.FormatConditions
        c.Delete
    Next
End Sub

© www.soinside.com 2019 - 2024. All rights reserved.