Hello,
I'm trying to use an IF-Then-Else Statement, but no matter what I try, I can't ever get it to work. It seems to hate me...
I've used two examples online. As written, they work using their own sample data. But if I make even one simple change, it fails, and I can't figure it out.
Any help with identifying where I'm going wrong would be greatly appreciated.
I tried stepping through the code in a standard Sub as well, but it was a NO GO. The purpose was to rule out any potential issues with using the Worksheet_SelectionChange considering I want the conditional formatting to be applied as scores are either being entered or updated.
The following code is based on the following YouTube video:
Following along from this video:
I'm trying to use an IF-Then-Else Statement, but no matter what I try, I can't ever get it to work. It seems to hate me...
I've used two examples online. As written, they work using their own sample data. But if I make even one simple change, it fails, and I can't figure it out.
Any help with identifying where I'm going wrong would be greatly appreciated.
I tried stepping through the code in a standard Sub as well, but it was a NO GO. The purpose was to rule out any potential issues with using the Worksheet_SelectionChange considering I want the conditional formatting to be applied as scores are either being entered or updated.
The following code is based on the following YouTube video:
VBA Code:
'Conditionally Format Scores when values are entered
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range
For Each cell In Range("tblScores[Score]")
If cell.Value > 0 And cell.Value <= 0.6 Then
cell.DisplayFormat.Interior.Color = 13551615 'light red
ElseIf cell.Value > 0.6 And cell.Value <= 0.8 Then
cell.DisplayFormat.Interior.Color = 10086143 'light yellow
ElseIf cell.Value > 0.8 And cell.Value < 1 Then
cell.DisplayFormat.Interior.Color = 11389944 'light orange
ElseIf cell.Value = 1 Then
cell.DisplayFormat.Interior.Color = 11854022 'light green
Else
cell.DisplayFormat.Interior.Color = 16777215 'default: no color
End If
Next cell
End Sub
Following along from this video: