Conditional Formatting in VBA with an Expression

naylorpsu

New Member
Joined
Apr 3, 2018
Messages
7
Good morning, everyone.

I have a static cell ($A$6) on worksheet that is the goal for the number of tickets that should worked on during the week.

Starting at cell (C11), I have a range labeled "rg" that is Dynamic and could span many columns depending on how many teams submitted tickets during that week. This shows the number of Tickets by each team submitted.

I would like to apply conditional formatting within VBA that goes through that range and calculates the following:

Condition 1: if greater than 10%, show in red (too many tickets processed)
Condition 2 : if less than -10%, show in yellow (not enough tickets processed)

This is what i have so far (see below), but not sure how to write the formula for the xlExpression (if i did this right to begin with).

Any help would be greatly appreciated. Thank you in advance! Please let me know if you need any clarification.



Sub C_ConditionalFormatting()

Dim rg As Range
Dim maxValue, minValue As Double

Set rg = Range("C11", Range("C11").End(xlToRight).Offset(0, -1))
Set maxValue = 0.1
Set minValue = -0.1

With Dashboard.Range(rg)

' CONDITION FOR GREATER THAN 10% - reference maxValue
.FormatConditions.Add xlExpression, Formula1:="=NEED FORMULA"
.FormatConditions(1).Interior.Color = RGB(255, 0, 0)

' CONDITION FOR LESS THAN -10% - reference minValue
.FormatConditions.Add xlExpression, Formula2:="=NEED FORMULA"
.FormatConditions(2).Interior.Color = RGB(255, 255, 0)

End With

End Sub
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Watch MrExcel Video

Forum statistics

Threads
1,118,400
Messages
5,571,907
Members
412,425
Latest member
MalCorn
Top