tourless
Board Regular
- Joined
- Feb 8, 2007
- Messages
- 144
- Office Version
- 365
- Platform
- Windows
Hi Folks.
I have this bit of code that is not working as expected. The goal is to highlight a cell with either a red font highlighted interior color if it's value is below or above a given benchmark. The benchmarks are different for each cell...
B21 - 3% or lower
C21 - 25% or higher
D21 - 20% or higher
E21 - 15% or lower
F21 - 15% or higher
G21 - 22% or lower
In some instance there is no value in the cell and in those cases I simply want to ignore the cell and move on. What's happening is even if a cell is blank, it ends up getting either a red font or highlighted interior as if there is a value in it. Here's what I'm working with... I can't wait to see how the guru's here compress this down to three or four lines of code.
I have this bit of code that is not working as expected. The goal is to highlight a cell with either a red font highlighted interior color if it's value is below or above a given benchmark. The benchmarks are different for each cell...
B21 - 3% or lower
C21 - 25% or higher
D21 - 20% or higher
E21 - 15% or lower
F21 - 15% or higher
G21 - 22% or lower
In some instance there is no value in the cell and in those cases I simply want to ignore the cell and move on. What's happening is even if a cell is blank, it ends up getting either a red font or highlighted interior as if there is a value in it. Here's what I'm working with... I can't wait to see how the guru's here compress this down to three or four lines of code.
VBA Code:
'Column B WTD +/-
If Range("B21") > 0.03 Then
Range("B21").Font.Color = 255
Else
If Range("B21") < 0.03 Then
Range("B21").Interior.Color = 65535
Else
End If
End If
'Column C WTD +/-
If Range("C21") < 0.25 Then
Range("C21").Font.Color = 255
Else
If Range("C21") >= 0.25 Then
Range("C21").Interior.Color = 65535
Else
End If
End If
'Column D WTD +/-
If Range("D21") < 0.2 Then
Range("D21").Font.Color = 255
Else
If Range("D21") > 0.2 Then
Range("D21").Interior.Color = 65535
Else
End If
End If
'Column E WTD +/-
If Range("E21") > 0.15 Then
Range("E21").Font.Color = 255
Else
If Range("E21") < 0.15 Then
Range("E21").Interior.Color = 65535
Else
End If
End If
'Column F WTD +/-
If Range("F21") < 0.15 Then
Range("F21").Font.Color = 255
Else
If Range("F21") > 0.15 Then
Range("F21").Interior.Color = 65535
Else
End If
End If
'Column G WTD +/-
If Range("G21") > 0.22 Then
Range("G21").Font.Color = 255
Else
If Range("G21") < 0.22 Then
Range("G21").Interior.Color = 65535
Else
End If
End If