Change worksheet tab color based on today's date

sadi

Board Regular
Joined
Jun 27, 2009
Messages
93
Hello Every Body,
I Have a worksheet that has sheets labeled 1-31 (one for each day of the month). How can I have the worksheet tab change color based on the date? For example; if when I open the workbook today is the 15th, sheet 15 would change its color tab to red. Tomorrow when I open the same workbook, I need sheet 15 tab to return to its original color and sheet 16 turn red?
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Thanks!

Sadi
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
you will need to add the following code to the Workbook....tell me if this works or not.....

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim i As String
i = Day(Now())
Sheets(i).Activate
With ActiveWorkbook.Sheets(i).Tab
.ColorIndex = xlNone
.TintAndShade = 0
End With
End Sub

Private Sub Workbook_Open()
Dim i As String
i = Day(Now())
Sheets(i).Activate
With ActiveWorkbook.Sheets(i).Tab
.Color = 255
End With
End Sub
 
Upvote 0
niceguy_jay

Thanks for your attention. It’s work, but when I want to close the workbook it’s give a run time error 438. If I want to Debug it show .TintAndShade = 0 this line. Please help.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Thanks again
 
Upvote 0
the code is not giving error to me..!!
try deleting this line (TintAndShade = 0) where it is giving error...
or else if you can share the workbook i can give a closer look...
 
Upvote 0
The TintAndShade issue will most likely relate to the Excel version being used. This property for worksheet tabs only appeared in Excel 2007.
 
Upvote 0
Thanks guys, It's work properly after deleting (TintAndShade = 0),<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
For your information I'm using Excel 2003<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,222,398
Messages
6,165,766
Members
451,986
Latest member
samwize

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