Color Code Dates in Excel

Mspearman

New Member
Joined
Dec 20, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I have two worksheets, second worksheet is linked to the first and provides color codes for dates for the second sheet. The for dates that are within 90 days form the date listed on sheet one the date turns green on sheet two, then amber for 60, red for 30, and gray for overdue. Is there a way to do this same function without having to link sheet two to sheet one? Is it possible to do this in VBA or use some other method? If so how?

Here are the formulas I used on sheet two to link to sheet one.

=EDATE(NUMBERVALUE('FORMULA SHEET'!B2),13)


=NUMBERVALUE('FORMULA SHEET'!C2)


=EDATE(NUMBERVALUE('FORMULA SHEET'!D2),NUMBERVALUE('FORMULA SHEET'!E2))


=EDATE(NUMBERVALUE('FORMULA SHEET'!F2),24)

E9EF29E5-4695-4404-8F63-056B813F6632.jpeg
0DF776C0-A4E7-4C03-A5F5-C83ABAE021D1.jpeg
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Here is the VBA to color the date.

VBA Code:
Sub ColorDate()

Dim NumberOfDay As Long
Dim DateA As Date, DateB As Date
Dim wb As Workbook
Dim wsA As Worksheet, wsB As Worksheet

Set wb = ThisWorkbook
Set wsA = wb.Sheets("A")      ' Define your sheet name here
Set wsB = wb.Sheets("B")

NumofDay = DateDiff("d", wsA.Range("A1"), wsB.Range("A1"))

Select Case NumberOfDay
    Case Is < 91
        wsB.Range("A1").Interior.ColorIndex = 4                   'Green
    Case Is < 121
        wsB.Range("A1").Interior.ColorIndex = 44                 ' Orange
    Case Is < 151
        wsB.Range("A1").Interior.ColorIndex = 3                   ' Red
    Case Else
        wsB.Range("A1").Interior.ColorIndex = 16                 ' Gray
End Select

End Sub

You can refer to color from any website such as
 
Upvote 0
Zot,

Thank you for your help with this I will give it a try and let you know how it turns out!
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

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