使用VBA将条件格式应用于一系列单元格 [英] Using VBA to apply conditional formatting to a range of cells
问题描述
我想知道如何使用标题为适用于的条件格式访问列,并输入自己的条件。
我已经添加了一个屏幕截图,以便更好地参考。
我添加条件格式化语法的代码是
选择
.FormatConditions.Delete
.FormatConditions.Add类型:= xlExpression,Formula1:==& c。地址& = TRUE
。
。
。
结束与
我相信该代码应该添加在那里,但我找不到正确的语法。
更新:
我更新了我的代码, ,(b),单元格(c.Row,N))
.FormatConditions.Delete
.FormatConditions.Add类型:= xlExpression,Formula1:==& c.Address
.FormatConditions(1).Interior.ColorIndex = 15'更改为其他颜色,当勾选
结束与
这将基本上使具体范围的行与我放置复选框的位置相关,并改变其背景颜色。
复选框位置由c.Address表示,其中'c'包含我选择放置复选框的单元格的位置。
你需要这样做( Range(A25)
正是你要找到的):
With Range(A25)
.FormatConditions.Delete
.FormatConditions.Add类型:= xlExpression,_
Formula1:==& c.Address
'。
'。
'。
结束
,没有必要写= & c。地址& = TRUE
,您只能使用=& c.Address
。
I would like to know how to access the column in conditional formatting titled 'Applies To' and input my own conditions. I have included a screenshot for better reference.
My code for adding the syntax in conditional formatting is,
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=" & c.Address & "=TRUE"
.
.
.
End With
I believe the code should be added in there but i just cannot find the correct syntax.
Update :
I updated my code to look like this,
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
This would essentially make rows of a specific range relevant to where i placed the checkbox, have their background colour changed. The checkbox position is represented by c.Address where 'c' contains the location of the cell that i selected to place my checkbox.
You need to do something like this (Range("A25")
is exactly what you are going to find):
With Range("A25")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=" & c.Address
'.
'.
'.
End With
and there is no need to write "=" & c.Address & "=TRUE"
, you can use just "=" & c.Address
.
这篇关于使用VBA将条件格式应用于一系列单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!