gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:33:38 24 4
gpt4 key购买 nike

我想知道如何访问条件格式中标题为“适用于”的列并输入我自己的条件。我提供了一个屏幕截图以供更好的引用。

Applies To column

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

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

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

最佳答案

您需要执行以下操作(Range("A25") 正是您要找到的内容):

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

不需要写"="& c.Address & "=TRUE",直接使用"="& c.Address即可。

关于vba - 使用 VBA 将条件格式应用于一系列单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21280803/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com