Results 1 to 3 of 3

Thread: IF 'x & y' are Both Zero THEN colorize 'a'

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    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

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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:
    1. For Each f In Range("E6:E6").Cells
    2.         Select Case f.Value
    3.             Case 0.955 To 999999999
    4.                 f.Interior.ColorIndex = 41
    5.             Case 0.805 To 0.95499
    6.                 f.Interior.ColorIndex = 4
    7.             Case 0.795 To 0.80499
    8.                 f.Interior.ColorIndex = 6
    9.             Case 0.015 To 0.79499
    10.                 f.Interior.ColorIndex = 3
    11.             Case 0 To 0
    12.                 If Range("H6") = 0 And Range("I6") = 0 Then
    13.                     f.Interior.ColorIndex = 41
    14.                 Else
    15.                     f.Interior.ColorIndex = 3
    16.                 End If
    17.             Case Else
    18.         End Select
    19.     Next
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    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
  •  



Click Here to Expand Forum to Full Width