I wanted the cell colors to change according to the value it hold. So I have used the following code in my excel sheet. The code works, but it is very slow.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = True
If Target.Column = 31 Or Target.Column = 34 Or Target.Column = 37 Or Target.Column = 40 Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Target = UCase(Target)
If Target.Value = "P" Then Target.Interior.ColorIndex = 4
If Target.Value = "F" Then
Target.Interior.ColorIndex = 3
Target.Offset(0, 1).Select
End If
If Target.Value = "B" Then
Target.Interior.ColorIndex = 24
Target.Offset(0, 1).Select
End If
If Target.Value = "N" Then Target.Interior.ColorIndex = 6
End If
End Sub
Can anyone help me in improving the speed or optimizing the code.
Thanks in Advance,
Saravana Babu Srinivasan
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = True
If Target.Column = 31 Or Target.Column = 34 Or Target.Column = 37 Or Target.Column = 40 Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Target = UCase(Target)
If Target.Value = "P" Then Target.Interior.ColorIndex = 4
If Target.Value = "F" Then
Target.Interior.ColorIndex = 3
Target.Offset(0, 1).Select
End If
If Target.Value = "B" Then
Target.Interior.ColorIndex = 24
Target.Offset(0, 1).Select
End If
If Target.Value = "N" Then Target.Interior.ColorIndex = 6
End If
End Sub
Can anyone help me in improving the speed or optimizing the code.
Thanks in Advance,
Saravana Babu Srinivasan