code to change font colour after certain date

smokenack

Active Member
Joined
Dec 12, 2003
Messages
351
Hi,

I'm trying to write some code that upon opening the workbook will change the font colour of a certain range if a certain date has passed. I also want to stop users being able to change the font colour after the code has changed it.

The following

Sub MARKNUTS()
If (TODAY) > 39901 Then
Worksheets("Sheet1").Range("A1:Z500").Font.ColorIndex = 4
End If
End Sub

does nothing. As always I can't remember how to post code tags (sorry) and can't remember the upon opening bit.

thanks for looking

Nick
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
In the ThisWorkBook module. Right Click the excel icon left of "File" on the menu bar and choose "View Code"
Code:
Private Sub Workbook_Open()
If (TODAY) > 39901 Then
    Sheet1.Unprotect "password"
    Worksheets("Sheet1").Range("A1:Z500").Font.ColorIndex = 4
    Sheet1.Protect "password"
End If
End Sub
lenze

BTW: Regular Conditional Formatting should work, as it will override any manually introduced formatting.
 
Last edited:
Upvote 0

smokenack

Active Member
Joined
Dec 12, 2003
Messages
351
Thanks for that Lenze but still no luck. I've pasted the code into the ThisWorkbook module but nothing happens upon opening with or without the Sheet protected.

Nick
 
Upvote 0

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
I should have caught that!! :oops: :oops: TODAY is not a VBA function. You might, however, use DATE instead of NOW
lenze
 
Upvote 0

Forum statistics

Threads
1,191,558
Messages
5,987,274
Members
440,087
Latest member
Ruppert23

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
Top