【发布时间】:2015-10-25 14:24:25
【问题描述】:
我整天都在与这个问题作斗争,但不知道为什么会这样。
每当我使用 VBA(并且因为通过 Excel 的 GUI)添加新的条件格式时,它都不会让我根据该行的第一个单元格中的文本编写一个公式来突出显示该行。不,为了让这更令人困惑,我稍后在 sub 中有几乎相同的代码,它们做同样的事情(使用不同的文本),但 Excel 没有给我一个错误。
下面给我一个运行时错误“5”无效的过程或参数
Range("A10", Range("A10").Offset(ItemsCount - 1, CLPCount + 2)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=IF($A10=""Duplication"",TRUE,FALSE)"
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).StopIfTrue = False
并且说我应该使用“=”,当我尝试运行代码时,它告诉我存在语法问题。
Range("A10", Range("A10").Offset(ItemsCount - 1, CLPCount + 2)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add(Type:=xlExpression, Formula1:="=IF($A10=""Duplication"",TRUE,FALSE)")
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).StopIfTrue = False
然后,如果我从公式中删除绝对引用列的 $,它会毫无问题地通过,但不提供所需的功能。如果我将 " 放在单元格引用周围,也是一样。
================================================ ==============================
非常感谢提供帮助的人。 除了我,我们都很好,我错了,也对了……这就是我运行 Excel 的方式。 Excel 在 R1C1 公式模式下运行,因此问题出在在此模式下使用 Excel 时条件格式的公式中使用的单元格引用样式。
【问题讨论】:
标签: excel excel-formula excel-2007 conditional-formatting vba