单元格格式需要随着单元格值的改变而改变

Cell formats need to change with changing cell value

我使用以下代码将条件格式应用于工作表。问题是,如果我改变 Formula1:=Cells(11,7) [例如] 中的值,格式化数据不会反映更新后的变化。当我打开 Excel 的 条件格式规则管理器 时,规则不显示对实际单元格的引用,而是我 运行宏。有什么想法吗?

Dim i As Integer

For i = 7 To 13
    Range(Cells(21, i), Cells(118, i)).Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
        Formula1:=Cells(11, i)

    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With


    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:=Cells(13, i)

    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
       .PatternColorIndex = xlAutomatic
       .ColorIndex = 6
       .TintAndShade = 0
    End With
Next

使用这样的代码设置公式 1 属性。

Formula1:="=Cells(11, " & i & ")"

你想要的是更像Formula1:="=$G"的东西:

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
        Formula1:="=" & Cells(11, i).Address()