0

我想向一个单元格添加条件格式,但条件的值是另一个单元格。

条件应进入此单元格:Cells(x, cellcounter)

If Cells(x, cellcounter) > 0 then Cells(y, cellcounter) color RGB(153, 199, 112)

这是我想出的,但它给了我一个错误。什么是正确的语法?

Cells(cell_quote_paid, cellcounter).FormatConditions.Add(Cells(cell_pending, cellcounter), xlGreater, "=0").Interior.Color = RGB(153, 199, 112)

谢谢你的帮助!

4

1 回答 1

0

在 Excel 2010 中,不需要 VBA。

  1. 将 Excel 光标放在单元格 (y, cellcounter) 中,然后从主页功能区的样式部分单击 [条件格式] - [新规则...]
  2. 单击“使用公式确定要格式化的单元格
  3. 将光标放在“格式化此公式为真值的值”字段中
  4. 单击单元格(x,单元格计数器)...它将显示例如 =$A$1(即提供您的条件的单元格的参考)
  5. 将“>0”添加到公式并选择格式

您可以使用 [条件格式] - [管理规则...] 将相同的规则应用于多个单元格,因此如果条件单元格从 0 变为 1,则所有单元格将变为红色。

要在 VBA 中执行相同操作,请使用以下方法和属性:

{target range}.FormatConditions.Add Type:=xlExpression, Formula1:="=$A$1>0"
{target range}.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
{target range}.FormatConditions(1).Font.Color = RGB(153, 199, 112)
{target range}.FormatConditions(1).StopIfTrue = False
于 2013-08-02T11:19:44.623 回答