Conditional Formatting VBA

trevormay99

New Member
Joined
Aug 25, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
I have a code that organizes raw data into multiple sheets, without getting into too much detail, it lists the task from the raw data with short descriptions, and completed date as well as scheduled date for each of the tasks, if the task was completed late (after the schedule date) I want it to be shaded red, if it was completed on time or early, then shaded green. However I am having trouble creating a code to apply this conditional formatting. I also need it to be applied to all sheets, is this possible or will it run too slow to be useful.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
What columns are these dates in? Is this true for all sheets in the workbook?
Might these columns contain any blanks, and if so, how would you like those to be handled?

In cases like this, it is often valuable to see a sample of your data so we can see how your data is structured, if there are headers/trailers/blank rows, etc.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
I will try to get the add in to work, for now here is a snip, column F contains the date completed, column L contains the targeted scheduled date, so if F<=L (green shade) if F > L red shade

for areas with blanks shade yellow

Capture1.PNG
 
Upvote 0
Installed the add in here you go
Macro Fix V1.xlsm
ABCDEFGHIJKL
1Scheduling Report
2ELECT
3Work OrderWO DescriptionWO Long DescriptionProcessAsset PrioritySchedule DateStatusTypeAssetLaborCraftTarget Date
4W23D11804Carry-over Section - Equipment/Process Improvement - ElectricalNeed Two Process button installed 1 on the drive side of the carry over section and 1 on the operator side of the carry over section they will both need conduit and boxes installed74/6/23RELEASEDEPIM674440.00Elect
5W23D11803Backing Film Applicator - Equipment/Process Improvement - Electricalneed a process stop install on an exiting electrical box to the north of the backing film station its number is 0410PS2334/8/23RELEASEDEPIM669440.00Elect
6W23D15958Limestone Pre Crusher Catwalks/Frame/Stairs - Corrective - Post-Repair - ElectricalRun Conduit for for heater cords on pre crusher See Modline Zack 14/22/23RELEASEDCORQ00211.00Elect
7W23D13469IKO4WLS Dragon Tooth Pull Roll Lane #4 - 4 Month Life Cycle 1 - Mechanical- Removal of Dragon Tooth Pull Rolls - Inspections to perform - Replacement of Dragon Tooth Pull Rolls - Speed MatchSTOP75/8/23WSCHEDLIFS47300.25Elect5/8/23
8W23D13476IKO4WLS Dragon Tooth Pull Roll Lane #1 - 4 Month Life Cycle 1 - Mechanical- Removal of Dragon Tooth Pull Rolls - Inspections to Perform - Replacement of Dragon Tooth Pull Rolls - Speed MatchSTOP75/8/23WSCHEDLIFS47320.25Elect5/8/23
Pre-Meeting
 
Upvote 0
Additionally, I have come across an issue in which this particular table generates twice, once at A3 and again at LH3, cannot figure out the error in the code
 
Upvote 0
Try this code:
VBA Code:
Sub MyCFRules()

    Dim ws As Worksheet
    Dim lr As Long
    Dim rng As Range
    
'   Loop through all sheets
    For Each ws In ActiveWorkbook.Worksheets
'       Find last row with data in column A
        lr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'       Set range to format
        Set rng = ws.Range("A3:L" & lr)
'       Set up first CF rule
        With rng
            .FormatConditions.Add Type:=xlExpression, Formula1:="=$F3>$L3"
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
            With .FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = 255
                .TintAndShade = 0
            End With
        End With
'       Set up second CF rule
        With rng
            .FormatConditions.Add Type:=xlExpression, Formula1:="=$F3<=$L3"
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
            With .FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = 5296274
                .TintAndShade = 0
            End With
            .FormatConditions(1).StopIfTrue = True
        End With
'       Set up third CF rule
        With rng
            .FormatConditions.Add Type:=xlExpression, Formula1:="=$L3="""""
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
            With .FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = 65535
                .TintAndShade = 0
            End With
            .FormatConditions(1).StopIfTrue = True
        End With
    Next ws
        
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,126
Messages
6,123,200
Members
449,090
Latest member
bes000

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