Excel has a Conditional Formatting... option under the Format menu that allows you to change the style/color/font/whatever of a cell depending upon its value. But it only allows three conditions.
How do I get Excel to display say, six different background cell colors depending upon the value of the cell? (IE Make the cell red if the value is "Red", and blue if "Blue" etc.)
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules. Select the command you want, such as Between, Equal To Text that Contains, or A Date Occurring. Enter the values you want to use, and then select a format.
On the Data tab, in the Sort & Filter group, click Sort. In the Sort dialog box, under Column, in the Sort by box, select the column that you want to sort. Under Sort On, select Cell Color, Font Color, or Cell Icon.
Click Format. In the Format Cells dialog box, click the Fill tab. Select the background or pattern color that you want to use for the shaded rows, and then click OK.
In Excel, there is no direct way for you to filter rows by multiple colors, but, you can create a VBA code to return the color index number of the corresponding row in a new column, and then filter the rows by this helper column.
You will need to write something in VBA.
See example here: Get Around Excels 3 Criteria Limit in Conditional Formatting:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("A1:A10")) is Nothing Then
Select Case Target
Case 1 To 5
icolor = 6
Case 6 To 10
icolor = 12
Case 11 To 15
icolor = 7
Case 16 To 20
icolor = 53
Case 21 To 25
icolor = 15
Case 26 To 30
icolor = 42
Case Else
'Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
Excel 2007 allows more than three conditions. Quoting from this Microsoft page:
EDIT: Ah, there's a "feature" in the linking code: parentheses in a link cited in parentheses aren't being handled correctly. That link is: http://msdn.microsoft.com/en-us/library/bb286672(office.11).aspx
Other benefits of the changes to conditional formatting in Excel 2007 are the ability to specify more than three conditions, to reorder conditions, and to have more than one condition resolve to True.
Otherwise. you're stuck with messy alternatives as described, I'm afraid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With