This is my first post to the forum, but I have been an observer for quite a while. I am fairly new to VBA in excel and have run into a problem I am not sure how to resolve.
Code
Private Sub Worksheet_Change(ByVal Target As Range)
'Color cells based on Selection
If Target.Address = "$C$10" Then
Application.EnableEvents = False
If Range("C10").Value = "COVERAGE" Then
'N/A
Range("C19:C23").Interior.ColorIndex = xlColorIndexNone 'Highlight Cells
Range("C19:C23").Interior.ColorIndex = 15 'Highlight cells
Range("C19:C23").ClearContents ' Clears Item
Range("C40:C45").Interior.ColorIndex = xlColorIndexNone 'Highlight Cells
Range("C40:C45").Interior.ColorIndex = 15 'Highlight cells
Range("C40:C45").ClearContents ' Clears Item
ElseIf Range("C10").Value = "CONSUMABLE" Then
'Consumable
Range("C19:C23").Interior.ColorIndex = xlColorIndexNone 'Highlight Cells
Range("C40:C45").Interior.ColorIndex = xlColorIndexNone 'Highlight Cells
Range("C20:C23").Interior.ColorIndex = 15 'Highlight cells
Range("C20:C23").ClearContents ' Clears Item
Range("C40:C45").Interior.ColorIndex = 15 'Highlight cells
Range("C40:C45").ClearContents ' Clears Item
End If
Application.EnableEvents = True
End If
End Sub
Display More
I would like this to apply to columns D, E, F, and G (Meaning if Cell D10 = Coverage, cells D19:D23 are cleared and colored, etc). I know I could just repeat the code above, substituting Column D for Column C, but I’m sure there has to be a more efficient way. Any help would be greatly appreciated.