jcaptchaos2
Well-known Member
- Joined
- Sep 24, 2002
- Messages
- 1,032
- Office Version
- 365
- Platform
- Windows
SyndeyGeek posted this code which is exactly what I need but I can't get it to work on formulas, is there a way? If I type the number in the cell it works fine but if I have a formula in the cell that the result changes the color does not.
Dennis
Thanks for this code I found by searching, Can you tell me if there is anyway to get it to work if the cell is a formula?
Dennis
Thanks for this code I found by searching, Can you tell me if there is anyway to get it to work if the cell is a formula?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iColor As Integer
' Multiple Conditional Format
Dim rng As Range
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
Set rng = Range("E10:E208")
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
Select Case Target.Value
Case Is > Range("J2").Value
iColor = 20
Case Is > Range("J3").Value
iColor = 44
Case Is > Range("J4").Value
iColor = 15
Case Is > Range("J5").Value
iColor = 46
Case Else
iColor = 0
End Select
Target.Interior.ColorIndex = iColor
End Sub
The break values are in J2:J5, sorted descending. They could just as easily be links to another sheet.
BTW, I used Select Case because it's easier to maintain if you add or remove conditions.
You'll also need this code in a standard module to set the starting formats:
Code:
Sub SetFormats()
Dim iColor As Integer
Dim c as Range
For Each c in Range("E10:E208")
Select Case c.Value
Case Is > Range("J2").Value
iColor = 20
Case Is > Range("J3").Value
iColor = 44
Case Is > Range("J4").Value
iColor = 15
Case Is > Range("J5").Value
iColor = 46
Case Else
iColor = 0
End Select
c.Interior.ColorIndex = iColor
Next c
End Sub
[/Qoute]