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
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,884
Messages
6,175,174
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top