killing a sub from within an if statement
Just ot be a little different. Why not create a flag variable and loop for so
long as the flag is true. Something like this...
Dim blnProcced as boolean
blnProceed = true
Range("A4:w4").Select
Do Until blnProceed = False
'Moves #1 PM info down until date matches #4 PM date
If ActiveCell.Value < ActiveCell.Offset(0, 12).Value Then
ActiveCell.Offset(0, 12).Resize(, 11).Insert shift:=xlDown
MsgBox "Loop #1 Column A < Column M"
'If #4Pm's date is greater then #1 PM's date then shift #4 down.
ElseIf ActiveCell.Value ActiveCell.Offset(0, 12).Value Then
ActiveCell.Resize(, 12).Insert shift:=xlDown
MsgBox "Loop #2 Column A Column M
End If
If ActiveCell.Value = ActiveCell.Offset(0, 12).Value And
ActiveCell.Offset(1, 12).Value = "" Then
MsgBox "A = M AND M = Blank"
Kill statement needs to go here
blnProceed = False
End If
ActiveCell.Offset(1, 0).Select
Loop
Doing it this way you can end the loop when every you want by changing the
boolean flag. I find Exit Sub to be problematic sometimes. There is a rule of
thumb that procedures and functions should have only one entry point and only
one exit point. This way you know that all of the code in the procedure was
addressed. Some of it may have been skipped, but all of it had the
opportunity to run...
HTH
HTH
"Cliff L" wrote:
I am trying to stop a sub from continueing once a set of values i.e. null in
2 cells is attained. Can anyone help me?
Range("A4:w4").Select
Do Until ActiveCell.Value = ""
'Moves #1 PM info down until date matches #4 PM date
If ActiveCell.Value < ActiveCell.Offset(0, 12).Value Then
ActiveCell.Offset(0, 12).Resize(, 11).Insert shift:=xlDown
MsgBox "Loop #1 Column A < Column M"
'If #4Pm's date is greater then #1 PM's date then shift #4 down.
ElseIf ActiveCell.Value ActiveCell.Offset(0, 12).Value Then
ActiveCell.Resize(, 12).Insert shift:=xlDown
MsgBox "Loop #2 Column A Column M
End If
If ActiveCell.Value = ActiveCell.Offset(0, 12).Value And
ActiveCell.Offset(1, 12).Value = "" Then
MsgBox "A = M AND M = Blank"
Kill statement needs to go here
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
|