Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default stop calling sub Intentionally without error.

Hi all,
I am trying to find a way to stop all sub's from running if certain
conditions are encountered. sin the example below, if row count is
less than 50 I would like to stop sub_1 from running. All of the
posts i find on this subject are related to errors. this isn't really
an error just a condition. Thanks for any advice. BRC

sub _1()
call sub_2
do some stuff
end sub

sub_2()
if range ("somerange").rows.count <50 then
msgbox("Less than 50 rows")
exit sub
else
end sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default stop calling sub Intentionally without error.

You should write your Sub_2 as a Function procedure that returns True
if execution is to continue or False if execution should cease. E.g.,


Function Proc2()
If Range("SomeRange").Rows.Count < 50 Then
Proc2 = False
Else
Proc2 = True
End If
End Function

Then, in Sub_1,

Sub Sub_1()
Dim Continue As Boolean
Continue = Proc2()
If Continue = False Then
Exit Sub
End If
' more code
End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]





On Tue, 12 Jan 2010 10:43:24 -0800 (PST), BRC
wrote:

Hi all,
I am trying to find a way to stop all sub's from running if certain
conditions are encountered. sin the example below, if row count is
less than 50 I would like to stop sub_1 from running. All of the
posts i find on this subject are related to errors. this isn't really
an error just a condition. Thanks for any advice. BRC

sub _1()
call sub_2
do some stuff
end sub

sub_2()
if range ("somerange").rows.count <50 then
msgbox("Less than 50 rows")
exit sub
else
end sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default stop calling sub Intentionally without error.

Instead of performing the "less than 50" test in sub_2, why not do it in
sub_1?

Sub sub_1()
If Range("somerange").Rows.Count < 50 Then
MsgBox "Less than 50 rows!"
Exit Sub
End If
Call sub_2
' do some stuff
End Sub

Sub sub_2()
' do some stuff
End Sub

--
Rick (MVP - Excel)


"BRC" wrote in message
...
Hi all,
I am trying to find a way to stop all sub's from running if certain
conditions are encountered. sin the example below, if row count is
less than 50 I would like to stop sub_1 from running. All of the
posts i find on this subject are related to errors. this isn't really
an error just a condition. Thanks for any advice. BRC

sub _1()
call sub_2
do some stuff
end sub

sub_2()
if range ("somerange").rows.count <50 then
msgbox("Less than 50 rows")
exit sub
else
end sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default stop calling sub Intentionally without error.

On Jan 12, 10:53*am, Chip Pearson wrote:
You should write your Sub_2 as a Function procedure that returns True
if execution is to continue or False if execution should cease. E.g.,

Function Proc2()
* * * * If Range("SomeRange").Rows.Count < 50 Then
* * * * * * * * Proc2 = False
* * * * Else
* * * * * * * * Proc2 = True
* * * * End If
End Function

Then, in Sub_1,

Sub Sub_1()
* * * * Dim Continue As Boolean
* * * * Continue = Proc2()
* * * * If Continue = False Then
* * * * * * * * Exit Sub
* * * * End If
* * * * ' more code
End Sub

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLCwww.cpearson.com
[email on web site]

On Tue, 12 Jan 2010 10:43:24 -0800 (PST), BRC



wrote:
Hi all,
I am trying to find a way to stop all sub's from running if certain
conditions are encountered. sin the example below, if row count is
less than 50 I would like to stop sub_1 from running. *All of the
posts i find on this subject are related to errors. this isn't really
an error just a condition. *Thanks for any advice. BRC


sub _1()
call sub_2
do some stuff
end sub


sub_2()
if range ("somerange").rows.count <50 then
msgbox("Less than 50 rows")
exit sub
else
end sub- Hide quoted text -


- Show quoted text -


thank you for the quick responses. I thought i read somewhere that
using smaller sections of code where more efficient and make debug
easier. also I thouht that having several sub routines to do
differnt things might be a better approach then writing one long
macro. Given all that, Chip I am not sure how Sub Sub_1() in your
example knows that the Function Proc2() ended in true (or false).
Thanks again for the help

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default stop calling sub Intentionally without error.

On Jan 12, 11:30*am, BRC wrote:
On Jan 12, 10:53*am, Chip Pearson wrote:





You should write your Sub_2 as a Function procedure that returns True
if execution is to continue or False if execution should cease. E.g.,


Function Proc2()
* * * * If Range("SomeRange").Rows.Count < 50 Then
* * * * * * * * Proc2 = False
* * * * Else
* * * * * * * * Proc2 = True
* * * * End If
End Function


Then, in Sub_1,


Sub Sub_1()
* * * * Dim Continue As Boolean
* * * * Continue = Proc2()
* * * * If Continue = False Then
* * * * * * * * Exit Sub
* * * * End If
* * * * ' more code
End Sub


Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLCwww.cpearson.com
[email on web site]


On Tue, 12 Jan 2010 10:43:24 -0800 (PST), BRC


wrote:
Hi all,
I am trying to find a way to stop all sub's from running if certain
conditions are encountered. sin the example below, if row count is
less than 50 I would like to stop sub_1 from running. *All of the
posts i find on this subject are related to errors. this isn't really
an error just a condition. *Thanks for any advice. BRC


sub _1()
call sub_2
do some stuff
end sub


sub_2()
if range ("somerange").rows.count <50 then
msgbox("Less than 50 rows")
exit sub
else
end sub- Hide quoted text -


- Show quoted text -


thank you for the quick responses. *I thought i read somewhere that
using smaller sections of code where more efficient and make debug
easier. *also I thouht that having several sub routines *to do
differnt things might be a better approach then writing one long
macro. *Given all that, *Chip I am not sure how Sub Sub_1() in your
example knows that the Function Proc2() ended in true (or false).
Thanks again for the help- Hide quoted text -

- Show quoted text -


Never mind, I see how that happens. Thanks again.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to intentionally set a variable to 'error' (iserror(x) = true) ker_01 Excel Programming 4 August 26th 08 05:12 PM
Intentionally not validate Sub or Function Troubled User Excel Programming 4 September 11th 07 04:20 AM
Intentionally truncating text characters Doug Excel Discussion (Misc queries) 2 June 22nd 07 12:22 AM
Error 49: Bad .dll Calling Convention Jarrett Sadowsky Excel Programming 1 January 20th 04 07:52 PM
Bad DLL Calling Convention (Error 49) Shaikh Excel Programming 3 November 18th 03 10:18 PM


All times are GMT +1. The time now is 09:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"