使用VBA将条件格式应用于一系列单元格

我想知道如何访问标题为“适用于”的条件格式的列,并input我自己的条件。 我已经包含了一个截图,以供参考。

应用于列

我的条件格式添加语法的代码是,

With Selection .FormatConditions.Delete .FormatConditions.Add Type:=xlExpression, Formula1:="=" & c.Address & "=TRUE" . . . End With 

我相信代码应该添加在那里,但我找不到正确的语法。

更新:

我更新了我的代码,看起来像这样,

 With Range(Cells(c.Row, "B"), Cells(c.Row, "N")) .FormatConditions.Delete .FormatConditions.Add Type:=xlExpression, Formula1:="=" & c.Address .FormatConditions(1).Interior.ColorIndex = 15 'change for other color when ticked End With 

这基本上会使特定范围的行与我放置checkbox的位置相关,并更改其背景颜色。 checkbox的位置由c.Address表示,其中“c”包含我select放置checkbox的单元格的位置。

你需要做这样的事情( Range("A25")正是你将要find的):

 With Range("A25") .FormatConditions.Delete .FormatConditions.Add Type:=xlExpression, _ Formula1:="=" & c.Address '. '. '. End With 

而且不需要写"=" & c.Address & "=TRUE" ,你可以使用"=" & c.Address

“适用于”是在With块执行的select中固有的。