|
-
Oct 17th, 2005, 01:22 PM
#1
Thread Starter
Junior Member
IF 'x & y' are Both Zero THEN colorize 'a'
How do I edit the red area of code to do an IF THEN color?
IF H6 and I6 are both zeros
THEN colorize "E6" as blue (Interior.ColorIndex = 41)
(in the Select Case f, it changes "E6" to red if it sees a zero result...which is correct, *UNLESS* H6 and I6 are BOTH zeros....then, the user should not be penalized with a red rating -- because BOTH being zeros indicates there was no data that month to calculate....(so, turn the red back to blue before ending the run if H6 and I6 are true)....if it's false....then I'm lost in how to tell it to go ahead and leave it at red..? Can you help guide me with Select Case g?
Code:
Sub test()
Dim c As Range, d As Range, e As Range, f As Range, g As Range
For Each c In Range("E3:E3").Cells
Select Case c.Value
Case 0 To 1
c.Interior.ColorIndex = 41
Case 2 To 20
c.Interior.ColorIndex = 4
Case 21 To 30
c.Interior.ColorIndex = 6
Case 31 To 999999999
c.Interior.ColorIndex = 3
Case Else
End Select
Next
For Each d In Range("E4:E4").Cells
Select Case d.Value
Case 0 To 0.89499
d.Interior.ColorIndex = 3
Case 0.895 To 0.95499
d.Interior.ColorIndex = 6
Case 0.955 To 0.98499
d.Interior.ColorIndex = 4
Case 0.985 To 999999999
d.Interior.ColorIndex = 41
Case Else
End Select
Next
For Each e In Range("E5:E5").Cells
Select Case e.Value
Case 0 To 0.01499
e.Interior.ColorIndex = 41
Case 0.015 To 0.10499
e.Interior.ColorIndex = 4
Case 0.105 To 0.15499
e.Interior.ColorIndex = 6
Case 0.155 To 999999999
e.Interior.ColorIndex = 3
Case Else
End Select
Next
For Each f In Range("E6:E6").Cells
Select Case f.Value
Case 0.955 To 999999999
f.Interior.ColorIndex = 41
Case 0.805 To 0.95499
f.Interior.ColorIndex = 4
Case 0.795 To 0.80499
f.Interior.ColorIndex = 6
Case 0.015 To 0.79499
f.Interior.ColorIndex = 3
Case 0 To 0
f.Interior.ColorIndex = 3
Case Else
End Select
Next
For Each g In Range("E6:E6").Cells
Select Case g.Value
Case 0 To 0
g.Interior.ColorIndex = 41
Case Else
End Select
Next
End Sub
-
Oct 17th, 2005, 01:29 PM
#2
Re: IF 'x & y' are Both Zero THEN colorize 'a'
Replace your fSelect Case with the following and it should work.
I've added an IF..THEN statement that sets the color to blue if the 2 reference cells are zeros, otherwise it set the color to red.
VB Code:
For Each f In Range("E6:E6").Cells
Select Case f.Value
Case 0.955 To 999999999
f.Interior.ColorIndex = 41
Case 0.805 To 0.95499
f.Interior.ColorIndex = 4
Case 0.795 To 0.80499
f.Interior.ColorIndex = 6
Case 0.015 To 0.79499
f.Interior.ColorIndex = 3
Case 0 To 0
If Range("H6") = 0 And Range("I6") = 0 Then
f.Interior.ColorIndex = 41
Else
f.Interior.ColorIndex = 3
End If
Case Else
End Select
Next
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Oct 17th, 2005, 01:46 PM
#3
Thread Starter
Junior Member
Re: IF 'x & y' are Both Zero THEN colorize 'a'
Great idea! - get rid of 'g' altogether!
(I'm still learning VBA) and LOVE to see how there's so many ways to make things work! THAT IS SO KOOL! -- it works perfectly! Thank you so VERY much!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|