在宏中,我使用以下代码:
With Range("T2:X31")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$R2=0"
.FormatConditions.Add Type:=xlExpression, Formula1:="=$AE2"
.FormatConditions.Add Type:=xlExpression, Formula1:="=$AF2"
.FormatConditions(1).Interior.Color = RGB(216, 216, 216)
.FormatConditions(1).Font.Color = RGB(216, 216, 216)
.FormatConditions(2).Interior.Color = RGB(255, 40, 40)
.FormatConditions(2).Font.Color = RGB(255, 255, 255)
.FormatConditions(3).Interior.Color = RGB(255, 128, 0)
.FormatConditions(3).Font.Color = RGB(0, 0, 0)
End With
当我检查条件格式规则时,我想在 excel 中得到什么(手动输入):
我得到的是
除了行(1046053 而不是 2),一切都很好。我应该如何输入单元格引用以获得正确的公式。
最佳答案
在设置条件之前尝试选择A2:
Range("A2").Select
我从未使用过 VBA,但我怀疑其条件格式中的公式与当前选择有关。
我认为最好选择您实际设置条件的范围,就像您从界面中进行的那样:
Range("T2:X31").Select
关于excel - 条件格式和 vba,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34659075/