Sunday, December 27, 2009

Programming Days of Week in Excel?

I am trying to create a VB script or macro that will change the font (to bold and underline) of a specific cell on a specific day of the week. I am also trying to do this for cells based on time of day. Does anyone know how I can accomplish this? Programming Days of Week in Excel?
Select the specific cell %26gt; Format %26gt; Conditional Formatting %26gt; Formula Is (in drop down box)





In the formula field enter


=WEEKDAY(TODAY())=2


to change the font on Mondays.





Select Format to set the format you want.





Change the 2 for other days of the week.





In the Conditional Formatting window select Add to specify more days for special formatting.





An example of Conditional formatting based on time would be to enter the formula as


=NOW()-INT(NOW())%26gt;TIMEVALUE(';14:45';)


to change the format at 2:45 PM





The issue with this is that the change will not take place until the first recalculation after the time.





To get a recalculation every time there is a selection change place Cells(1, 1) = Cells(1, 1) in the Worksheet_SelectionChange subroutine like below.





Private Sub Worksheet_SelectionChange(ByVal Target As Range)


Cells(1, 1) = Cells(1, 1)


End Sub





To get things any tighter would require timers and become quite complicated.

No comments:

Post a Comment