Home > Forum Home > Presenting and Reporting Data > Conditional Formatting Multiple 'IF Thens' With Specified Colors > Highlight cells based on values Share

Highlight cells based on values

Excel Help for Highlight Cells Based On Values in Presenting and Reporting Data


Forum TopicLogin

Highlight Cells Based On Values

Rate this:
(3/5 from 1 vote)
HappyThe following VBA macro will highlight today's date and yesterday's date. Of course it can be improved such as condtions modified and added as well as the formatting options.
VBA Code:
Sub highlightdates()
Application.ScreenUpdating = False
Dim c As Variant
For Each c In Selection
    MsgBox Now() - c.Value
    'Today
    If Now() - c.Value <= 1 Then
        c.Select
        With Selection.Interior
            .ColorIndex = 8
            .Pattern = xlSolid
        End With
    End If
    'Yesterday
    If Now() - c.Value > 1 And Now() - c.Value <= 2 Then
        c.Select
        With Selection.Interior
            .ColorIndex = 6
            .Pattern = xlSolid
        End With
    End If
Next
Application.ScreenUpdating = True
End Sub
 Excel Business Forums Administrator
 Posted by on
 
View Full Post

Find relevant Excel templates and add-ins for Highlight cells based on values in the