View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default killing a sub from within an if statement

Why the Goto? The loop will exit when the flag is false and the sub you can
terminate any objects through normal execution. This is kind of the point to
the boolean. You don't just exit the sub. You complete whtever code is
necessary.

"Ed" wrote:

Be careful of objects and variables not properly terminated when you Exit
Sub. I would personally lean towards Jim's method of using a Boolean and
throw in a GoTo:
If Boolean = True Then GoTo StopMe
....
....
StopMe:
Terminate all variables
Terminate all objects
End Sub

No need then for Exit Sub, and everything's nice and neat (hopefully).

Ed

"Cliff L" wrote in message
...
Thanks folks. I knew it was simple, I just don't have the brains.

"Alok" wrote:

Cliff

How about 'Exit Sub'?

Alok Joshi

"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