VB.Net: If 语句 While 条件格式

VB.Net: If Statement While Conditional Formatting

我正在尝试在我的条件格式设置示例中使用 if 语句。我已经能够成功地使用条件格式,但在弄清楚如何在其中合并 if 语句时遇到问题。 if 语句是...

IF cell I2 is not empty AND cell b2 < 1 mark the cell red.

IF (AND(I2 <> "", B2 < 1), Red?, not red?)

我觉得这里有两块拼图,但不确定如何将它们拼在一起。

条件格式代码:

protoWorksheet.Range("E2:E100").FormatConditions.Add(XlFormatConditionType.xlExpression, Type.Missing, "=E2=""Gap""").Interior.Color = RGB(255, 0, 0)

在VBA中使用公式时,如果要使用双引号,则必须加倍:

"=AND($I2<>"""",B2<1)"

否则,VBA 将读取到第二个单引号,并停止作为公式读取,因此之后的任何内容都可能会引发错误。

如果您想包含一些文字,例如:"=AND($I2=""My Words"",B2<1)"