Hi all,
I have a workbook in which I want to set the background color based on a specific value in each individual cell within a specific range (not the entire sheet) and I have five values I want to use (1 to 5).
I tried IF-Then-Else but didn't get the syntax right.
Just to clarify, if I type 1in cell A1, I want the background to be red, if I type 2, I want the background to be green etc..
I tried the following code with no luck.:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Selection.Value = 1 Then Selection.Interior.ColorIndex = 27 Else Selection.Interior.ColorIndex = xlNone
If Selection.Value = 2 Then Selection.Interior.ColorIndex = 3 Else Selection.Interior.ColorIndex = xlNone
If Selection.Value = 3 Then Selection.Interior.ColorIndex = 4 Else Selection.Interior.ColorIndex = xlNone
If Selection.Value = 4 Then Selection.Interior.ColorIndex = 32 Else Selection.Interior.ColorIndex = xlNone
If Selection.Value = 5 Then Selection.Interior.ColorIndex = 46 Else Selection.Interior.ColorIndex = xlNone
End Sub
Bookmarks