Style highlighter based on Date Conditions

Wee Kuang

Board Regular
Joined
Sep 15, 2011
Messages
59
Hello all,

Currently I'm trying to come up with a macro that is able to do some highlighting to cells, which contain dates that are two weeks past the current date. Below is my progress so far.

Sub date_highlight()

CurrentDate = Date
LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row

For n = 3 To LastRow
If Range("J" & n).Value < CurrentDate + 1 And Range("J" & n).Value > CurrentDate - 15 Then
Range("J" & n).Style = "Good"
End If
Next n

End Sub

When I run the macro, it keeps on showing a Run-time error '1004': Application-defined or object defined error.

I'm quite new to VBA and so any guidance or help will be much appreciated. Cheers! :)
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Ok. I inadvertently protected the worksheet that the code were suppose to work on. After I unprotect it, the code is working.
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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