Conditional Formatting (more than 3) in Excel

August 2017



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


Published by aakai1056. Latest update on October 20, 2016 at 10:02 AM by owilson.
This document, titled "Conditional Formatting (more than 3) in Excel," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).