Skip to content

Instantly share code, notes, and snippets.

@mrowles
Last active October 13, 2015 22:08
Show Gist options
  • Save mrowles/4263018 to your computer and use it in GitHub Desktop.
Save mrowles/4263018 to your computer and use it in GitHub Desktop.
Microsoft Excel: Changes the colour of a row based on a particular value in a cell
'Note: needs to be attached to a worksheet
Private Sub Worksheet_Change(ByVal Target As Range)
'Specifies the target column to pay attention to on worksheet change
If (Target.Column = 2) Then
'Conditional statement based on cell value
Select Case Target.Value
Case "red"
Worksheets("Sheet1").Rows(Target.Row).Interior.ColorIndex = 3
Case "blue"
Worksheets("Sheet1").Rows(Target.Row).Interior.ColorIndex = 5
Case "green"
Worksheets("Sheet1").Rows(Target.Row).Interior.ColorIndex = 4
Case Else
Worksheets("Sheet1").Rows(Target.Row).Interior.ColorIndex = xlNone
End Select
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment