+ Reply to Thread
Results 1 to 5 of 5

How to call a subroutine or continue with code depending on the sheetnames in the workbook

  1. #1
    Registered User
    Join Date
    10-01-2019
    Location
    London, England
    MS-Off Ver
    365
    Posts
    3

    How to call a subroutine or continue with code depending on the sheetnames in the workbook

    Hi,

    Trying to go from practically new user to (hopefully) a warmed up beginner, giving myself a crash course on macros by diving in and just doing it (I may be a bit over my head).

    I am having issues with one of my subroutines. I only want a specific subroutine to run if the workbook consists of 5 specific sheets. If it does not, I would like a different subroutine to be called. I can't find anything by searching so I can't even determine if it's possible, but I don't see why not.

    I don't even have any starting code because I don't know where to begin.

    To put it simply to call a next subroutine, I would like to run the following:

    If workbook contains all Sheet A, Sheet B, Sheet C, Sheet D, Sheet E, go to Sub X

    If not, go to Sub Y

    Is this possible?

    I thought I could use an "If Array Sheet ABCDE exists, call Sub X, else, call Sub Y", but I can't seem to get it to work.

    Please let me know if any additional clarification is needed.

    Thank you!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: How to call a subroutine or continue with code depending on the sheetnames in the work

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    10-01-2019
    Location
    London, England
    MS-Off Ver
    365
    Posts
    3

    Re: How to call a subroutine or continue with code depending on the sheetnames in the work

    Thank you so much! Just added this into my code and it appears to work great.

    Do you mind explaining how it works so I can better understand it? Mainly the GoTo Other/0 is where I'm lacking understanding.

    Thanks again.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: How to call a subroutine or continue with code depending on the sheetnames in the work

    Referencing an object that doesn't exist will result in an error - that allows you to use that error as an existence check: If Sheet A does not exist, the Set line will result in an error, allowing your code to move to the subroutine that you want to call if the workbook does not have Sheet A in it.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-01-2019
    Location
    London, England
    MS-Off Ver
    365
    Posts
    3

    Re: How to call a subroutine or continue with code depending on the sheetnames in the work

    Wonderful. Thank you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] call Subroutine
    By mena in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-11-2018, 07:47 AM
  2. [SOLVED] Message box if Yes continue with subroutine and if NO then exit sub and open sheet2
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-19-2014, 05:59 PM
  3. [SOLVED] In VBA code if a workbook that i have referenced is not there - how do i continue
    By m.collins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2012, 08:24 AM
  4. How to call a subroutine in another workbook
    By dgarris in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2008, 10:30 AM
  5. [SOLVED] how to update Listbox of sheetnames if user changes sheetnames?
    By tr00per in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-12-2006, 04:10 AM
  6. Call subroutine from another workbook
    By DejaVu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2005, 12:12 PM
  7. subroutine call with arguments
    By gabe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-11-2005, 06:21 PM

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