Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Condition formatting

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Condition formatting

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Condition formatting

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Condition formatting

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting / Condition Help ?? Kim Excel Discussion (Misc queries) 9 September 24th 09 03:59 PM
Conditional Formatting if a certain condition is met JerryG Excel Programming 2 August 4th 07 10:18 PM
Condition Formatting in code. How? Barb Reinhardt Excel Programming 0 August 11th 06 02:28 PM
I need 4 condition for condition formatting SeeKY Excel Programming 2 June 7th 05 09:41 AM
conditional formatting under a condition... fabalicious[_23_] Excel Programming 1 May 7th 04 03:38 PM


All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"