Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End if cell is blank 1

Status
Not open for further replies.

zebra99

Technical User
Sep 19, 2008
14
US
I have the following code working perfectly, but need to add one thing. If the current cell is blank I want the select case code to be ignored. Can you help?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCell As Range
For Each oCell In Range("I10:Z22")
myTot = oCell.Value
For i = 1 To 5
myTot = myTot + oCell.Offset(0, -i).Value
Next i
Select Case myTot
Case Is < 3
oCell.Interior.ColorIndex = xlNone
Case Is = 3
oCell.Interior.ColorIndex = 6
Case Is = 4
oCell.Interior.ColorIndex = 45
Case Is = 5
oCell.Interior.ColorIndex = 3
Case Is > 5
oCell.Interior.ColorIndex = 39
End Select
Next oCell
End Sub
 


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    For Each oCell In Range("I10:Z22")  '[b]
        If oCell.Value <> "" Then       '[/b]
            myTot = oCell.Value
            For i = 1 To 5
                myTot = myTot + oCell.Offset(0, -i).Value
            Next i
            Select Case myTot
                 Case Is < 3
                     oCell.Interior.ColorIndex = xlNone
                 Case Is = 3
                     oCell.Interior.ColorIndex = 6
                 Case Is = 4
                     oCell.Interior.ColorIndex = 45
                 Case Is = 5
                     oCell.Interior.ColorIndex = 3
                 Case Is > 5
                     oCell.Interior.ColorIndex = 39
             End Select     '[b]
        End If              '[/b]
    Next oCell
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top