View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Can't get out of loop at the right point

Bruce,

It is hard to make sense of your code, but you can exit out of a
loop with 'Exit For' or 'Exit Do', depending on your loop type.
This will take you to the line of code following the 'Next' or
'Loop' statement.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Bruce Roberson" wrote in message
...
I need to know how to exit the sub in the case below in
sub submonth at the end of this section.

Basically when the IF statement here is:
If Range("Row").Value Range("DataRows").Value Then
Exit Sub

The command to "exit sub" just sends me back to the
calling sub detailloop and the command line "next" is
encountered in this situation.

Is there a command such as "quit" that allows it to not go
back to the calling sub in this case?



Sub Process_data()
Things happen here only once then
Call HeaderRecord
End Sub

Sub HeaderRecord()
Loops and Things happen here then
Call detailloop
End Sub

Sub detailloop()
looping going on here then

If Range("Row").Value Range("DataRows").Value Then
Call summonth
Else
If Range("New_Prmo") Then
Call summonth

Else
End If
End If
Next (refers to a loop that is not shown in this post)
End Sub

Sub summonth()
Range("rowsum").Value = Range("Rowsum").Value + 1
If Range("Row").Value Range("DataRows").Value Then
Exit Sub
Else
Call HeaderRecord
End If
End Sub