Change color of cell when dates match (4 conditions)

ceslyn

New Member
Joined
Mar 4, 2009
Messages
48
Anyone can tell me how to make this work?
I'm always getting the amount of 40611 and my cells are not changing.

Any help would be appreciated.

Thanks!


Sub findate()
Dim strDate1, strDate2 As Date
strDate1 = myplage
strDate2 = Now
testdates = DateDiff("d", strDate1, strDate2)
msgbox (testdates)
Set myplage = Range("B6:N18")
For Each cell In myplage
testdates = DateDiff("d", strDate1, strDate2)
If testdates > 5 Then Range("b6").Interior.Color = RGB(200, 160, 35)
If testdates < 5 Then Range("b6").Interior.Color = RGB(255, 255, 255)
If testdates = 5 Then Range("b6").Interior.Color = RGB(50, 50, 50)
Next
End Sub
 
Finally working, Thank a lot Andrew for helping me out.

Here is the final code. I still need to correct the IF statements.

Thanks again!!!!!


Sub CellsExample()
Dim Startdate As Date
Dim Enddate As Date
Startdate = Cells(3, 1).Value
Enddate = Now
For i = 6 To 6
For j = 2 To 14
If Cells(i, j).Value <> "" Then
Enddate = Cells(i, j).Value

testdates = DateDiff("y", Startdate, Enddate)
If testdates > 365 Then Cells(i, j).Interior.Color = RGB(200, 160, 35)
If testdates > 730 Then Cells(i, j).Interior.Color = RGB(50, 50, 50)
If testdates = 0 Then Cells(i, j).Interior.Color = RGB(255, 255, 255)
If testdates < 40609 Then Cells(i, j).Interior.Color = RGB(255, 255, 255)
msgbox (testdates)
Startdate = Cells(3, 1).Value
Else
End If

Next j
Next i





End Sub
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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