[英]Excel 2007 - VBA - Apply Conditional Format on Range Based on Cell Values
For some reason, I can't figure out why the same formula that I can apply to conditional formatting regularly doesn't work in VBA. 由于某些原因,我无法弄清楚为什么我可以定期将相同的公式应用于条件格式在VBA中不起作用。 I'm trying to highlight the row in that range if one of the cells in each row is not blank.
如果每行中的单元格之一不为空,则尝试突出显示该范围内的行。
Below is the code I'm working with: 以下是我正在使用的代码:
With Range("$A3:$L1000")
.FormatConditions.Delete
.FormatConditions.Add xlExpression, Formula1:="=($J3)<>"""""
.FormatConditions(1).Interior.ColorIndex = 46
End With
When it applies to the document, here's the formula in Conditional Formatting 适用于文档时,这是条件格式中的公式
Any help/advice you all could provide would be greatly appreciated. 大家都可以提供的任何帮助/建议将不胜感激。
Update: 更新:
I solved this by recording a macro where I assigned the conditional formatting to a single line, copied the formatting, then pasted it over the active range. 我通过记录一个宏来解决这个问题,在宏中我将条件格式分配给了一行,复制了格式,然后将其粘贴到活动范围内。
Thanks to everyone for your input, and hope this helps someone else down the road! 感谢大家的投入,希望这对以后的人有所帮助!
Code 码
Range("A3:M3").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=($J3)<>"""""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.