Hello Grimace,
This macro will ignore limit cells that are empty. There must be both a lower and upper limit for a test to be valid. The cell colors have been moved into an array to make selection easier.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim arrColors As Variant
Dim cell As Range
Dim CellType As Integer
Dim CI As Long
Dim ColorRng As Range
Dim FC As Long
Dim I As Long
Dim MyRange As Range
Dim Test1 As Range
Dim Test2 As Range
ActiveSheet.Unprotect Password:="Virgin11"
Set MyRange = Range("B2:M35")
Set ColorRng = Range("B38:I38")
'Exit if the selected cell or cells are not part of MyRange
If Intersect(Target, MyRange) Is Nothing Then Exit Sub
'Cell colors for test ranges
arrColors = Array(4, 45, 27, 3)
For Each cell In Target
CellType = VarType(cell)
'Default cell and font colors
CI = xlColorIndexNone
FC = xlColorIndexAutomatic
'Test if Target value is text
If CellType = vbString Then
cell.Interior.ColorIndex = 1
cell.Font.ColorIndex = 2
Else
'Value must be an Integer, Long, Single or Double
If CellType > 1 And CellType < 6 Then
For I = 1 To ColorRng.Cells.Count Step 2
'Get the lower and upper test range limits
Set Test1 = ColorRng.Cells(1, I)
Set Test2 = Test1.Offset(0, 1)
'Get the test range color if the cell value is in limits
'Don't test if one or both limits is/are empty cells
If Test1.Value <> "" And Test2.Value <> "" Then
If cell >= Test1 And cell <= Test2 Then
CI = arrColors(I \ 2)
End If
End If
Next I
cell.Interior.ColorIndex = CI
cell.Font.ColorIndex = FC
End If
End If
Next cell
ActiveSheet.Protect Password:="Virgin11"
End Sub
Bookmarks