[英]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.