Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Cell Background Colors in Excel Spreadsheets

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.)

like image 890
Michael Avatar asked Nov 06 '08 16:11

Michael


People also ask

How do you make multiple cells change color based on value?

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.

How do you group colored cells in Excel?

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.

How do I fill multiple rows in Excel with color?

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.

How do I filter by multiple colors in Excel?

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.


2 Answers

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
like image 79
Galwegian Avatar answered Oct 06 '22 00:10

Galwegian


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.

like image 21
Mike Woodhouse Avatar answered Oct 05 '22 23:10

Mike Woodhouse