Change Fill color and font type based on date VBA help

JeremyA1976

Board Regular
Joined
Aug 3, 2015
Messages
59
Hi all,
I have a VBA code I am using that will change a specific cell in column L to a fill of yellow or icolor=6 if it matches todays date. If the date in column L is before todays date, I want it to turn red or icolor=3. (I would prefer if it would stay yellow for 3 days instead of 1 day, but I can live with that). So our receiving manager gets a warning when something is overdue. If the date in the column is beyond todays date, I want it to be white fill or icolor=2, so he knows it is still out for delivery. The problem is... When I insert a date and then delete it, the cell turns red and I am not sure why. Anyone have any clue why this is happening? Code is below.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)    Dim icolor As Integer
    Dim cell As Range


    If Intersect(Target, Range("L3:L10000")) Is Nothing Then Exit Sub


    For Each cell In Target
        icolor = 0
        Select Case cell
            Case Is = Date: icolor = 6
            Case Is > Date: icolor = 2
            Case Is < Date + 1: icolor = 3
            Case "": icolor = 2
            
        End Select
        If icolor <> 0 Then cell.Interior.ColorIndex = icolor
    Next cell
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try
Code:
        Select Case cell
            Case "": icolor = 2
            Case Is = Date: icolor = 6
            Case Is > Date: icolor = 2
            Case Is < Date + 3: icolor = 3
        End Select
 
Upvote 0
That's right, an empty cell is less than today's date
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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