Conditional Formatting (more than 3) in Excel

December 2016



Issue

I am trying to apply more than three options to excel that changes the background color of the cell.

my range is R7:R1000

I need a VBA or macro that will change the background color of the cell as follows

if cell reads "Extreme", change background to red

If Cell reads "High" change background to Purple

If Cell reads "Medium", change background to yellow

If cell reads "Low" change background to green

If cell is empty, do nothing


Any assistance would be much appreciated

Solution

Try with this macro, you have to write in Visual Basic Editor :

Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPlage = Range("R7:R1000")
For Each Cell In MyPlage

If Cell.Value = "Extreme" Then
Cell.Interior.ColorIndex = 3
End If
If Cell.Value = "Hight" Then
Cell.Interior.ColorIndex = 4
End If
If Cell.Value = "Medium" Then
Cell.Interior.ColorIndex = 18

End If
If Cell.Value = "Low" Then
Cell.Interior.ColorIndex = 6
End If

If Cell.Value <> "Extreme" And Cell.Value <> "Hight" And Cell.Value <> "Medium" And Cell.Value <> "Low" Then
Cell.Interior.ColorIndex = xlNone
End If

Next
End Sub

Note

Thanks to aquarelle for this tip on the forum.

Related :

This document entitled « Conditional Formatting (more than 3) in Excel » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.