I am trying to implement conditional formatting in VBA using a countif formula. It does work for the moment but I would like to implement a variable range. I have tried the following without success
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
How to make the range within the countif dynamic. I have tried that:
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
Formula:="=COUNTIF($c$7:" & cells(r,c).Address & ";""B"")"using r, and c as the row and column numbers of the last cell in your dynamic range.