Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Conditional Formatting for %

Wanting to make a cell change color if it hits one of these criteria:
between 1% and -1% then green
between 1% and 5% then orange
greater than 5% then purple
between -1% and -5% then yellow
less than -5% then red

What can I do to the following script to make it work?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim cel As Range
Dim FormatRange As Range

Set FormatRange = Range("A1:H875")

If Not Application.Intersect(Target, FormatRange) Is Nothing Then

For Each cel In FormatRange

Select Case cel.Value
Case Is <= 0.01, Is = -0.01
cel.Interior.ColorIndex = 4
Case Is <= 0.04999999999, Is = 0.01000000001
cel.Interior.ColorIndex = 27
Case Is = 0.05
cel.Interior.ColorIndex = 7
Case Is <= -0.01000000001, Is = -0.0499999999999
cel.Interior.ColorIndex = 44
Case Is <= -0.05
cel.Interior.ColorIndex = 3
Case Else
cel.Interior.ColorIndex = xlColorIndexNone
End Select

Next cel

End If

End Sub


Much appreciated,
Bill
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Conditional Formatting for %

In order for this to work, you have to change a field that's in the range you
call FormatRange. If the cells in FormatRange have calculations in them,
you'll need to look at FormatRange.Precedents

HTH,
Barb Reinhardt

"b1llt" wrote:

Wanting to make a cell change color if it hits one of these criteria:
between 1% and -1% then green
between 1% and 5% then orange
greater than 5% then purple
between -1% and -5% then yellow
less than -5% then red

What can I do to the following script to make it work?

Private Sub Worksheet_Change(ByVal Target As Range)

Dim cel As Range
Dim FormatRange As Range

Set FormatRange = Range("A1:H875")

If Not Application.Intersect(Target, FormatRange) Is Nothing Then

For Each cel In FormatRange

Select Case cel.Value
Case Is <= 0.01, Is = -0.01
cel.Interior.ColorIndex = 4
Case Is <= 0.04999999999, Is = 0.01000000001
cel.Interior.ColorIndex = 27
Case Is = 0.05
cel.Interior.ColorIndex = 7
Case Is <= -0.01000000001, Is = -0.0499999999999
cel.Interior.ColorIndex = 44
Case Is <= -0.05
cel.Interior.ColorIndex = 3
Case Else
cel.Interior.ColorIndex = xlColorIndexNone
End Select

Next cel

End If

End Sub


Much appreciated,
Bill

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 cells in a column with conditional formatting? shamor Excel Discussion (Misc queries) 8 May 19th 08 10:11 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 3 January 20th 07 02:02 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM


All times are GMT +1. The time now is 08:55 AM.

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

About Us

"It's about Microsoft Excel"