ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   return from subroutine (https://www.excelbanter.com/excel-programming/297416-return-subroutine.html)

inquirer

return from subroutine
 
I have a program which calls a subroutine which in turn calls another
subroutine as in this schematic..

main program
call suba(z)
end
sub suba(z)
some code
call subb(x)
more code
end sub

sub subb(x)
some code
if x 100 then return
more code
end sub

When x 100 in subb, the progam returns to the main program and not to
suba.

Can someone tell me what I am doing wrong please?

Thanks
Chris








Norman Jones

return from subroutine
 
Hi Chris,

Try changing the line:

if x 100 then return
To:
if x 100 then exit sub

---
Regards,
Norman

"inquirer" wrote in message
...
I have a program which calls a subroutine which in turn calls another
subroutine as in this schematic..

main program
call suba(z)
end
sub suba(z)
some code
call subb(x)
more code
end sub

sub subb(x)
some code
if x 100 then return
more code
end sub

When x 100 in subb, the progam returns to the main program and not to
suba.

Can someone tell me what I am doing wrong please?

Thanks
Chris










Melanie Breden

return from subroutine
 
I have a program which calls a subroutine which in turn calls another
subroutine as in this schematic..


When x 100 in subb, the progam returns to the main program and not to
suba.

Can someone tell me what I am doing wrong please?


try this:

Sub subb(x)
'some code
If x 100 Then End
'more code
End Sub

or:

Sub suba(z)
'some code
Call subb(x)
If x < 100 Then
'more code
End If
End Sub

Sub subb(x)
'some code
If x < 100 Then
'more code
End If
End Sub

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)


inquirer

return from subroutine
 
Simple when you know how - thanks a lot

Chris


"Melanie Breden" wrote in message
...
I have a program which calls a subroutine which in turn calls another
subroutine as in this schematic..


When x 100 in subb, the progam returns to the main program and not to
suba.

Can someone tell me what I am doing wrong please?


try this:

Sub subb(x)
'some code
If x 100 Then End
'more code
End Sub

or:

Sub suba(z)
'some code
Call subb(x)
If x < 100 Then
'more code
End If
End Sub

Sub subb(x)
'some code
If x < 100 Then
'more code
End If
End Sub

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)





All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com