Sub ColourBasedOnColumnD2()
'
ActiveSheet.Unprotect 'place at the beginning of the code
Dim myC As Range
Dim myV As Variant
Dim myR As Range
Set myR = Range("A:C")
With Intersect(myR, Range(ActiveSheet.PageSetup.PrintArea))
.Offset(1, 0).Resize(.Rows.Count - 1).Interior.ColorIndex = xlNone
End With
For Each myC In Range(Range("D2"), Cells(Rows.Count, 4).End(xlUp))
' myV = Application.VLookup(IIf(IsEmpty(myC.Value), "", myC.Value), _
Range("ColorKey"), 2, False) ' code to handle just a named range
myV = Application.VLookup(IIf(IsEmpty(myC.Value), "", myC.Value), _
Worksheets("ColorKey").Range("A:B"), 2, False) ' code
to handle a sheet
On Error GoTo NoColor:
If myC.Row Mod 2 = 0 Then Intersect(myC.EntireRow, myR).Interior.ColorIndex = myV
NextCell:
Next myC
'ActiveSheet.Protect ' place at end of code
' Re-protects sheet in case anything unprotects it, yet allows vb functioning to remain.
With ActiveSheet
.EnableAutoFilter = True
.Protect UserInterfaceOnly:=True
End With
Exit Sub
NoColor:
Intersect(myC.EntireRow, myR).Interior.ColorIndex = 3
Resume NextCell:
End Sub