Help: How do i calculate 40days after a date in cell and change that cell color when it hits the 40 day mark.

Status
Not open for further replies.

Sha

New Member
Joined
Oct 6, 2021
Messages
30
Office Version
  1. 2013
Platform
  1. Windows
Hi there,

I am really new with all this. I am trying to get any cells in col J to change font/cell color once the date in col J hits more than 40 days. But the VBA codes doesn't seem to work.
Below is the code I have...

Sub HighlightCells()

Dim DischargeDate As Date: Set DischargeDate = Range("J1:J3000")

Dim fortyDys As Integer: Set fortyDys = 40



For Each DischargeDate In DischargeDate.Cells

If DischargeDate.Value > DischargeDate.Value + fortyDys Then

DischargeDate.Interior.ColorIndex = 3

End If

Next DischargeDate



End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Status
Not open for further replies.

Forum statistics

Threads
1,216,309
Messages
6,130,001
Members
449,551
Latest member
MJS_53

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