+ Reply to Thread
Results 1 to 4 of 4

Return subroutine value to main routine

  1. #1
    Registered User
    Join Date
    09-17-2010
    Location
    Aalsmeer, the Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Return subroutine value to main routine

    I got a simple question related to programming in Excel for the programming guru's out there. I created an offer template which generates up to 10 sheets. Everytime the user generates the offer sheets, the old sheets will be deleted first, and then new sheets will be generated.

    To seal any unwanted errors off i created a "Sub" and a Function to create new sheets, which return an error if the sheet already exists. Im not sure which of the two to use. (no one to discuss it with either.)

    so the questions are:
    - which method is preferred and why
    - would you solve it different

    i suppose i could also use a For Each [sheet] ..Next statement to check if a sheet exists and even cancel the event before the sheet(x).copy occurs.

    But then still i want to return some boolean value from my "create sheet" subroutine to my main routine

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 11-03-2010 at 05:11 AM. Reason: "Excel Programming: " removed from title
    Your constructive critisism is greatly appreciated!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Excel Programming: Return subroutine value to main routine

    My post here contains a function that I use to check if a sheet already exists
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    09-17-2010
    Location
    Aalsmeer, the Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Excel Programming: Return subroutine value to main routine

    Ok thats one idea.
    Good riddance error handling.
    That would change both functions to something like this:

    Please Login or Register  to view this content.
    Question remains which of the two methods would be preferred from the programming structure point of view
    if the function returns False, the entire program should stop, and i'd like to do so with avoiding global variables as much as possible
    Last edited by Mark Heuckeroth; 11-03-2010 at 04:54 AM.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Excel Programming: Return subroutine value to main routine

    Not really sure why your main code needs to be a Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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