Worksheet_Change

  • Thread starter Thread starter Greg Bloom
  • Start date Start date
Greg

The WorkSheet_Change event has a Target Parameter. When a cell is changed
you can test Target.Row and Target.Column. Search the archives for
WorkSheet_Change; you should find lots of examples.

One example for colouring cells dependent on their value:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Row < 3 Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
Select Case Int(Target.Value)
Case 1: Target.Interior.ColorIndex = 3 'red
Case 2: Target.Interior.ColorIndex = 36 'amber/yellow
Case 3: Target.Interior.ColorIndex = 27 'amber/dark yellow
Case 4: Target.Interior.ColorIndex = 4 'green
Case 5: Target.Interior.ColorIndex = 10 'dark green
Case Else: Target.Interior.ColorIndex = xlNone
End Select
End Sub

Regards

Trevor
 
Back
Top