Following is the code I regularly use when I need Conditional Formatting with more than four conditions. This code works great when you are typing in new data over the old, but I now need to base the formatting on data found in another sheet. For example, in Sheet1 and cell B2 I have a formula that reads =AVERAGE('Sheet2'!$B2:$D40), with this code the conditional formatting in cell B2 does not update when changes occur in Sheet2. To make this work, I thought I could modify the Event Procedure Code to run when Sheet1 is activated. This sounds like it should be easy and a common issue, but I have made several attempts in tweaking this code and searched several forums to ideas, but no luck thus far. Any thoughts are appreciated.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim CellColor As Integer
If Not Intersect(Target, Range("B2:D8")) Is Nothing Then
Select Case Target
Case 4.5 To 5
CellColor = 10
Case 4 To 4.4
CellColor = 36
Case 3 To 3.9
CellColor = 45
Case 2 To 2.9
CellColor = 3
Case 1 To 1.9
CellColor = 13
End Select
Target.Interior.ColorIndex = CellColor
End If
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim CellColor As Integer
If Not Intersect(Target, Range("B2:D8")) Is Nothing Then
Select Case Target
Case 4.5 To 5
CellColor = 10
Case 4 To 4.4
CellColor = 36
Case 3 To 3.9
CellColor = 45
Case 2 To 2.9
CellColor = 3
Case 1 To 1.9
CellColor = 13
End Select
Target.Interior.ColorIndex = CellColor
End If
End Sub