Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need to write a macro that fills in the background color of a column based
on the cell contents. It has five different possible conditions and all 5 need different colors. Excel 2003 Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Got my code!!!
Sub Color() Set Rank = Range("C2:C20") For Each Cell In Rank If Cell.Value = "Needs Improvement" Then Cell.Interior.ColorIndex = 3 End If If Cell.Value = "Below Requirements" Then Cell.Interior.ColorIndex = 45 End If If Cell.Value = "Meets Requirements" Then Cell.Interior.ColorIndex = 6 End If If Cell.Value = "Exceeds" Then Cell.Interior.ColorIndex = 4 End If If Cell.Value = "Superstar" Then Cell.Interior.ColorIndex = 8 End If If Cell.Value < "Needs Improvement" And Cell.Value < "Below Requirements" And Cell.Value < "Meets Requirements" And Cell.Value < "Exceeds" And Cell.Value < "Superstar" Then Cell.Interior.ColorIndex = xlNone End If Next End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why don't you use a select-case statement instead of those funky if
statements? Just type "select" put your cursor in front of select and hit H1 for a help example. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is some worksheet event code.
Private Sub Worksheet_Change(ByVal Target As Range) Set r = Range("A1:A100") 'adjust to suit If Intersect(Target, r) Is Nothing Then Exit Sub End If vals = Array("C", "D", "G", "H", "K") 'values nums = Array(8, 9, 6, 3, 7) 'colors For Each RR In r icolor = 0 For I = LBound(vals) To UBound(vals) If UCase(RR.Value) = vals(I) Then icolor = nums(I) End If Next If icolor 0 Then RR.Interior.ColorIndex = icolor End If Next End Sub Right-click on the sheet tab and "View Code" Copy/paste the code into that sheet module. Edit to suit your needs. Gord Dibben MS Excel MVP On Sun, 1 Mar 2009 20:43:01 -0800, Chad Portman wrote: I need to write a macro that fills in the background color of a column based on the cell contents. It has five different possible conditions and all 5 need different colors. Excel 2003 Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Formatting / Condition Help ?? | Excel Discussion (Misc queries) | |||
Conditional Formatting if a certain condition is met | Excel Programming | |||
Condition Formatting in code. How? | Excel Programming | |||
I need 4 condition for condition formatting | Excel Programming | |||
conditional formatting under a condition... | Excel Programming |