Conditional Formatting with VBA

MurraySMTH

Board Regular
Joined
Jun 30, 2020
Messages
81
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I am having issues with writing a code for conditional formatting for dates in my J and I columns.

If J is greater than or equal to column I, I wanted to highlight that green.

I know i could do this with the usual conditional formatting, but i will be using this report often and it will be replaced.
 

Attachments

  • Capture.JPG
    Capture.JPG
    52.9 KB · Views: 1

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
If you turn on your Macro Recorder, and record yourself setting up the Conditional Formatting, you will have most of the code that you need.
If you need help generalizing it (i.e. dynamically finding the last row to apply it to), just paste the code that you have recorded here, and we can help you edit it to do that.
 
Upvote 0
This is what i got. It works, but will it work on every report i pull?




Attribute VB_Name = "Module2"



Sub Appt4lessthanequaltoHSD()

Attribute Appt4lessthanequaltoHSD.VB_ProcData.VB_Invoke_Func = " \n14"

'

' Appt4lessthanequaltoHSD Macro

'



'

Columns("I:J").Select

Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$J2<=$I1"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

With Selection.FormatConditions(1).Interior

.PatternColorIndex = xlAutomatic

.ThemeColor = xlThemeColorAccent6

.TintAndShade = 0.599963377788629

End With

Selection.FormatConditions(1).StopIfTrue = False

Range("J9").Select

End Sub
 
Upvote 0
It looks like it should. Try it out of a few files to verify.
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,216
Members
449,215
Latest member
texmansru47

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