More than 3 conditional formats

kaptep

New Member
Joined
Feb 9, 2004
Messages
17
I Need to be able to format a large range of cells according to the number that they contain. Basically the cells are numbered 1-12 based on a variety of equations from other data and are updated frequently. I need the cells to be 12 different colors based on the value. Conditional formatting works great but only for 3 conditions. What is the easiest way to expand my conditions? I have read several tips for similar scenarios, but I cannot get any of the code to execute. :oops: Please give me some suggestions!!!
 
My pleasure, weve certainly covered a bit of ground. :biggrin:

Just a quick note, if you want to use the RGB type way or a mixture of both then you dont need the icolor variable but instead use the Color or ColorIndex property depending on the colour you want for that number.

eg.
Code:
Private Sub Worksheet_Activate()
Dim c, Rng As Range

'Range where you will update formatting (NB: Only cells with a formula
'are looked at)
Set Rng = Range("A1:Z500").SpecialCells(xlCellTypeFormulas)

'Loop through every cell in the range and apply formatting
    For Each c In Rng
        Select Case c.Value
        Case 1
            c.Interior.ColorIndex = 6
        Case 2
            c.Interior.ColorIndex = 12
        Case 3
            c.Interior.Color = RGB(0, 255, 0)
        Case 4
            c.Interior.Color = RGB(255, 255, 0)
        Case 5
            c.Interior.ColorIndex = 15
        Case 6
            c.Interior.ColorIndex = 42
        Case Else
            c.Interior.ColorIndex = 0 'no color
        End Select
  Next c

'Free memory
Set Rng = Nothing

End Sub

See ya.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,214,523
Messages
6,120,042
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top