如何在 Excel 中逐行设置条件格式色标

How can I conditional format color scale row-by-row in Excel

我有以下数据:

target_gene A   B   C   D
LETMD1  2.479   1.784   2.446   2.172
HHEX    0.343   0.010   0.313   0.166
CLNK    0.000   0.090   0.000   0.000
TAL1    0.000   0.000   0.041   0.000

并且使用 Microsoft Excel,我手动 条件格式 -> 色阶

一行一行的内容,结果如下

实际上,我有几千行要处理。如何 我可以在 Excel 中方便地(或以编程方式)做到这一点吗?

我正在使用适用于 Macintosh 的 MS Excel v15.31。

借助宏录制器的一点帮助,您可以将它放在 For...Next 循环中

Sub formatRows()

    Dim r As Long

    With ThisWorkbook.Worksheets(1)
        For r = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
            With .Rows(r)
                .FormatConditions.AddColorScale ColorScaleType:=3
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                .FormatConditions(1).ColorScaleCriteria(1).Type = _
                    xlConditionValueLowestValue
                With .FormatConditions(1).ColorScaleCriteria(1).FormatColor
                    .Color = 13011546
                    .TintAndShade = 0
                End With
                .FormatConditions(1).ColorScaleCriteria(2).Type = _
                    xlConditionValuePercentile
                .FormatConditions(1).ColorScaleCriteria(2).Value = 50
                With .FormatConditions(1).ColorScaleCriteria(2).FormatColor
                    .Color = 16776444
                    .TintAndShade = 0
                End With
                .FormatConditions(1).ColorScaleCriteria(3).Type = _
                    xlConditionValueHighestValue
                With .FormatConditions(1).ColorScaleCriteria(3).FormatColor
                    .Color = 7039480
                    .TintAndShade = 0
                End With
            End With
        Next r
    End With

End Sub