Home / Sample Macros / Conditional Formatting

Conditional Formatting


This macro is used in this Grade Sheet. This macro basically checks the value of the cell being modified. If it is greater than 90 then it sets a blue color to the next cell in the same row. If it is less than 50, it sets a red color to the next cell in the same row. Else, the color is set as grey.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = false
On Error Goto ENEV
REM add your code below
If IsNumeric(Target) Then
Dim grade As Range
Set grade = Cells(Target.Row, Target.Column+1)
If IsNumeric(Target) Then
If Target < 50 Then
grade.Font.Color = RGB(255,0,0)
Else
If Target > 90 Then
grade.Font.Color = RGB(0,0,255)
Else
grade.Font.Color = RGB(137,137,137)
End If
End If
End If
End If
ENEV:
Application.EnableEvents = true
End Sub

    Ashutosh Kumar  08 Nov 2015 
    Nice
    bbgulrot _  22 Aug 2017 
    Cool



     RSS of this page