列名称的条件格式

问题描述

我有个小问题。我在查看另一列(B)的列(A)上有条件格式化。

过去,我使用VBA通过dat代码创建条件格式:

    Range("I3:I99").Select
    Selection.FormatConditions.Add Type:=xlExpression,Formula1:="=W1=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

虽然可以正常工作,但我的电路板未固定,新的列可以在它们之间到达。

我决定重命名“ W”列“ OPI” 并像这样更改我的代码:

    Range("I3:I99").Select
    Selection.FormatConditions.Add Type:=xlExpression,Formula1:="=OPI1=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
 

但是dat没有工作。而且没有更多的想法怎么写??

感谢您的帮助,祝您生活愉快

解决方法

请尝试下一个代码:

Sub TestValidationNamedRange()
 With Range("I3:I99")
    .FormatConditions.Add Type:=xlExpression,Formula1:="=" & Range("OPI").cells(3).Address(0,0) & "=0"
    .FormatConditions(.FormatConditions.count).SetFirstPriority
    With .FormatConditions(1).Font
        .Color = -16776961
        .TintAndShade = 0
    End With
    .FormatConditions(1).StopIfTrue = False
 End With
End Sub

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...