+ Reply to Thread
Results 1 to 3 of 3

Exiting a Sub

Hybrid View

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Question Exiting a Sub

    Hi all, first I'll submit the code and then the problem:

    Sub IndMthlyExistingMth_Udate()
    
    Dim blnUpdate As Boolean
    blnUpdate = Application.ScreenUpdating
    Application.ScreenUpdating = False
    
    'This Sub is used to run the updates on pre-existing updates.
    Application.Run "SourceTransfer"
    Application.Run "CleanDataReTransfer"
    Application.Worksheets("IndMthly").Select
    Application.ScreenUpdating = blnUpdate
    
    End Sub
    When I step into the "SourceTransfer" Sub, I have this code to make sure that there has been data inputted into the proper cell:

    If ActiveCell.Value = "Paste Here" Then MsgBox ("There is no data in the ""Insert"" sheet.")
    If ActiveCell.Value = "Paste Here" Then Exit Sub
    If this happens, I want to exit the "IndMthlyExistingMth_Udate" Sub without carrying on to the next line, being:
    Application.Run "CleanDataReTransfer"
    I've tried some boolean tests but I cannot make it work once the "SourceTransfer" exits it's Sub. Any Suggestions?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Exiting a Sub

    Change the sub to a function that returns True if the conditions are satisfied to continue, and test that in the calling routine.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Exiting a Sub

    Thanks shg, I'm going to try that. I have a meeting so I won't be able to right away but as soon as I do I will let you know the outcome. I've yet to work very much with functions, mostly just subs but I'll give it a go!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1