Tuesday, 5 August 2008

Excel Colour Conditional Formatting

 

I sometimes use excel like a calendar, and set the weekends to an different colour.

1. Select the cells
2. Select Format -> Conditional Formatting

image

3. Assuming that you have the date in column A, Add the following formula

=IF(WEEKDAY($A2)=1, TRUE, FALSE)

3. image 

Possibly use this macro:

Sub ColorWeekends()
'
' ColorWeekends Macro
' Macro recorded 05/08/2008 by Anthony Kendrick
'

    Rows("2:32").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(WEEKDAY($A2)=1, TRUE, FALSE)" ' 2 is the first row with data
    Selection.FormatConditions(1).Interior.ColorIndex = 11 ' 11 is blue
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(WEEKDAY($A2)=7, TRUE, FALSE)"
    Selection.FormatConditions(2).Interior.ColorIndex = 3 ' 3 is red
    Range("C21").Select


End Sub

No comments: