Conditional Formatting (more than 3) in Excel

Ask a question


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.
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team