[英]Trying to add all borders to range with variable row count in excel vba
[英]count if variable range vba
我正在尝试使用countif公式在VBA中实现条件格式。 目前确实可以,但是我想实现一个可变范围。 我尝试了以下但没有成功
With Range("AI7").FormatConditions _
.Add(xlExpression, Formula1:="=AND(COUNTIF($C$7:$AG$7;""B"")<=3;COUNTIF($C$7:$AG$7;""R"")<=5)")
.Interior.Color = RGB(185, 207, 203)
End With
如何使区域内的范围动态化。 我已经尝试过:
With Range("AI7").FormatConditions _
.Add(xlExpression, Formula1:="=COUNTIF(R[7]C[3], R[7]C[31])="B"")
.Interior.Color = RGB(248, 194, 203)
End With
这是做到这一点的一种方法。 无论您需要哪种方式,都必须动态地获取列字母,但是可以将其放入下面的sCol
变量中。
Dim sCol as String
sCol = "AG" 'you'll have to define the column in whatever way you need
With Range("AI7").FormatConditions _
.Add(xlExpression, Formula1:="=AND(COUNTIF($C$7:$" & sCol & "$7;""B"")<=3;COUNTIF($C$7:$" & sCol & "$7;""R"")<=5)")
.Interior.Color = RGB(185, 207, 203)
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.