【发布时间】:2019-02-12 15:44:34
【问题描述】:
我有以下情况: 如果范围内的值介于 -2 和 2 之间,我使用 FormatConditions 格式化一个范围以显示样式“Good”,如果不是,则使用以下代码显示样式“Bad”:
With Range("D46:AC53")
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(AND(D46<2,D46>-2),TRUE,FALSE)"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(198, 239, 206)
.TintAndShade = 0
End With
.Font.Color = RGB(0, 98, 0)
End With
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(AND(D46<2,D46>-2),FALSE,TRUE)"
With .FormatConditions(.FormatConditions.Count)
.SetFirstPriority
With .Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 199, 206)
.TintAndShade = 0
End With
.Font.Color = RGB(156, 0, 6)
End With
End With
这很好用。
现在,我想创建一个宏按钮,该按钮将定义如果所有范围“D46:AC53”都是“Good”,则在特定单元格中显示值“TRUE”。我使用了这段代码:
If Range("D46:AC53").Interior.Color = RGB(198, 239, 206) Then Range("c3").Value = "TRUE" Else Range("c3").Value = "FALSE"
即使范围 D46:AC53 看起来是“好”,按钮也会返回“假”。
你能帮帮我吗?我做错了什么?
谢谢, 亚历山德拉
我检查了使用第一个代码格式化的范围的填充颜色,使用右键单击并设置单元格格式,它显示我没有被填充。我使用 Excel 中 Styles 中的 Style“Good” 手动格式化 Range D46:AC53,这使得按钮宏起作用。
【问题讨论】:
-
Interior.Color没有检测到 CF 颜色 - 网上有很多。使用 displayformat 或您用于 CF 的标准。 -
我对 VBA 很陌生,我什么也找不到。您能帮我如何调整代码以使其正常工作吗?
-
我将第二个代码更改为:
If wstRev.Range("D46:AC53").DisplayFormat.Interior.ColorIndex = RGB(198, 239, 206) = 0 Then Range("c3").Value = "TRUE" Else Range("c3").Value = "FALSE",但无论我在该范围内使用什么颜色,它都会返回 TRUE。 -
不确定该方法是否有效,您可能需要检查每个单元格。使用 CF 标准更容易。如果在值介于 -2 和 2 之间时对单元格进行着色,请使用 COUNTIFs 检查有多少满足该值,以及它是否与范围的大小相同,宾果游戏。
-
感谢您的帮助!我还没有找到关于如何执行 this.l 的解决方案。继续努力……