Hi,
Thank you, in advance, for any contributions to this code.
The code below isn't formatting. Essentially, what I need this code to do is start in column "D", row 3, and search for dates, highlighting any date that is within -4 to +2 days of a date listed in A1. I want this to then jump to column "G" and do the same thing, continuing this process for every 3 columns, until it reaches the last column, "Y". The goal is to have any date -4 to -1 be yellow, 0 would be green and +1 and +2 blue. The cells in column "A" would also be either green or blue, depending on the date.
Sub Datecolor()
Dim i As Long, j As Long, myDate As Date
myDate = Cells(1, 1)
For j = 4 To 25 Step 3
For i = 3 To 10000
If Cells(i, j) = myDate - 4 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate - 3 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate - 2 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate - 1 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate + 0 Then Cells(i & j).Interior.ColorIndex = 35 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate + 1 Then Cells(i & j).Interior.ColorIndex = 37 And Cells(i, 1).Interior.ColorIndex = 37
If Cells(i, j) = myDate + 2 Then Cells(i & j).Interior.ColorIndex = 37 And Cells(i, 1).Interior.ColorIndex = 37
Next i
Next j
End Sub
Thank you, in advance, for any contributions to this code.
The code below isn't formatting. Essentially, what I need this code to do is start in column "D", row 3, and search for dates, highlighting any date that is within -4 to +2 days of a date listed in A1. I want this to then jump to column "G" and do the same thing, continuing this process for every 3 columns, until it reaches the last column, "Y". The goal is to have any date -4 to -1 be yellow, 0 would be green and +1 and +2 blue. The cells in column "A" would also be either green or blue, depending on the date.
Sub Datecolor()
Dim i As Long, j As Long, myDate As Date
myDate = Cells(1, 1)
For j = 4 To 25 Step 3
For i = 3 To 10000
If Cells(i, j) = myDate - 4 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate - 3 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate - 2 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate - 1 Then Cells(i & j).Interior.ColorIndex = 36 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate + 0 Then Cells(i & j).Interior.ColorIndex = 35 And Cells(i, 1).Interior.ColorIndex = 35
If Cells(i, j) = myDate + 1 Then Cells(i & j).Interior.ColorIndex = 37 And Cells(i, 1).Interior.ColorIndex = 37
If Cells(i, j) = myDate + 2 Then Cells(i & j).Interior.ColorIndex = 37 And Cells(i, 1).Interior.ColorIndex = 37
Next i
Next j
End Sub