G
Guest
I am using excel 2000 and having some problems with two particular cells
(which contained formulas) in my worksheet. I have been using both
conditional formatting and VBA to change the color of two cells according to
some conditions:
Change color in cell P18 and P21 to Green, if 0 <= P18 or P21 <= 1, else
change it to Red
I have tested both method seperately (VBA and Conditional Formatting) and
there is nothing wrong with the result except whenever the cell P18 value is
re-calculated to zero, it will ALWAYS stay as Red...
I have even try to force the formatting by giving an extra line of code to
make sure when the cell is zero, it will be red...but this is not the case.
VBA code for one cell:
Private Sub Worksheet_Calculate()
Dim ucell1 As Range
Dim ucell2 As Range
Dim lcell1 As Range
Dim lcell2 As Range
Dim tcell1 As Range
Dim tcell2 As Range
Set ucell1 = Range("R18")
Set lcell1 = Range("S18")
Set ucell2 = Range("R21")
Set lcell2 = Range("S21")
Set tcell1 = Range("P18")
Set tcell2 = Range("P21")
If (Range("P18") < ucell1 Or Range("P18") = ucell1) And (Range("P18") >
lcell1 Or Range("P18").Value = lcell1.Value) Then
Range("P18").Interior.ColorIndex = 29
ElseIf Range("P18").Value = lcell1.Value Then
Range("P18").Interior.ColorIndex = 29
ElseIf Range("P18") > ucell1 Or Range("P18") < lcell1 Then
Range("P18").Interior.ColorIndex = 3
End If
End Sub
I would be grateful if someone could provide some advices as to why the cell
stay on Red when it is zero?
Any help will be much appreciated
Best Regards
Casey Wong
(which contained formulas) in my worksheet. I have been using both
conditional formatting and VBA to change the color of two cells according to
some conditions:
Change color in cell P18 and P21 to Green, if 0 <= P18 or P21 <= 1, else
change it to Red
I have tested both method seperately (VBA and Conditional Formatting) and
there is nothing wrong with the result except whenever the cell P18 value is
re-calculated to zero, it will ALWAYS stay as Red...
I have even try to force the formatting by giving an extra line of code to
make sure when the cell is zero, it will be red...but this is not the case.
VBA code for one cell:
Private Sub Worksheet_Calculate()
Dim ucell1 As Range
Dim ucell2 As Range
Dim lcell1 As Range
Dim lcell2 As Range
Dim tcell1 As Range
Dim tcell2 As Range
Set ucell1 = Range("R18")
Set lcell1 = Range("S18")
Set ucell2 = Range("R21")
Set lcell2 = Range("S21")
Set tcell1 = Range("P18")
Set tcell2 = Range("P21")
If (Range("P18") < ucell1 Or Range("P18") = ucell1) And (Range("P18") >
lcell1 Or Range("P18").Value = lcell1.Value) Then
Range("P18").Interior.ColorIndex = 29
ElseIf Range("P18").Value = lcell1.Value Then
Range("P18").Interior.ColorIndex = 29
ElseIf Range("P18") > ucell1 Or Range("P18") < lcell1 Then
Range("P18").Interior.ColorIndex = 3
End If
End Sub
I would be grateful if someone could provide some advices as to why the cell
stay on Red when it is zero?
Any help will be much appreciated
Best Regards
Casey Wong