Exit sub question...

antaeusguy

Board Regular
Joined
Mar 8, 2010
Messages
81
Hi

I have 2 procedures - one is the main and the other one is for checking/validation.

It looks like this:

Sub Main()
...
Call CheckNValidation
...
...
End Sub

Sub CheckNValidation()
...
(Code which does some checking... if successful, go back to Main, if fail, Exit Sub)
...
Exit Sub
...
End Sub

The problem with the code is, If in the CheckNValidation() resulted in fail, it continued to go back to the Main()...

If I put the CheckNValidation inside Main, I would have no problem... but because the code in CheckNValidation is long and I wish to make this into a separate procedure, so I decided to split into two which the Main() calls up CheckNValidation().

Anyone could help me with this code would be much appreciated! :)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Does the validation sub return some sort of result?

If it does why not convert it to a function and then in the main sub just have something like this.


Code:
boolContinue = CheckNValidation()
 
If Not boolContinue Then Exit Sub

Or use End, but be careful - that stops all code as far as I know.:)
 
Upvote 0
Wow.. I'm impressed with this board, within an hour 2 replies on this thread! :)

Hmm... my CheckNValidation doesn't return a value... just using the basic flow control If... Then... End If.

But good idea! I could try a function to return a boolean value. :)

I'll try both ideas and see which would be best.

But thanks a lot for your great help guys!
 
Upvote 0
Don't ever use End on its own.
 
Upvote 0
Actually I should have said if it doesn't return a value you could convert it to a function that does return a value.:)
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top