Question : Checking for Negative Numbers not Working

This is attempting to find a any negative number in a range and display a message box and exit.  So far it doesn't do anything for the negative numbers it just continues on with the code.
I have tried a few variations of:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Dim myShapes2 As Shape
Dim lrow5 As Long
    lrow5 = Cells(Cells.Rows.Count, "F").End(xlUp).Row
    
Dim rng5 As Range, cell5 As Range
        Set rng5 = Range("F2:F" & lrow5)
        For Each cell5 In rng5
cell5.NumberFormat = "0"
        If cell5.Value < 0 Then
        
            For Each myShapes2 In ActiveSheet.Shapes
                Debug.Print myShapes2.Name
                myShapes2.Visible = msoTrue
            Next myShapes2
            MsgBox "No Negative Numbers"
            
            Exit Sub
            
        Exit For
        Next cell5

Answer : Checking for Negative Numbers not Working

Hi.

Try this Subroutine - checks a specified range for negative values and displays a messagebox as required.

Matt
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Public Sub CheckNegative()

Dim rng As Range
Dim cll

Set rng = Range("C:C") 'Change range to what you want

For Each cll In rng
    If cll.Value < 0 Then
        MsgBox "Negative value found"
        Exit Sub
    End If
Next

End Sub
Random Solutions  
 
programming4us programming4us