+ Reply to Thread
Results 1 to 8 of 8

Specific sheet name macro help

  1. #1
    Registered User
    Join Date
    08-08-2019
    Location
    CO
    MS-Off Ver
    Latest
    Posts
    12

    Specific sheet name macro help

    Hey all,

    I am looking for help with a VBA code. I want to the script to run through the work book and only perform clearing out certain cells on specifically named sheets and to continue to execute the rest of the functions if that sheet doesn't exist. The problem I am running into is sometimes these reports do not have all the sheets (some are not needed). For example I have 6 sheets in a template that I need to account for (among many other sheets). So say I have sheets named PS1, PS2, PS3, PS4, PS5, and PS6. Most of the time these reports only contain PS1 and PS2, but I need it to check for all and not return an error if they do not exist. I will supply what I have so far. The problem lies inbetween ' Power Supply Clear and ' First Few Page Clear. All the rest works as intended. Thanks in advance!

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    XL 2010,2016
    Posts
    11,815

    Re: Specific sheet name macro help

    Just loop through the sheets, if it equals a specific sheet name then clear the cells.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-08-2019
    Location
    CO
    MS-Off Ver
    Latest
    Posts
    12

    Re: Specific sheet name macro help

    Forgive my VBA ignorance, but am I to insert all of that code in between like so? I am including my entire macro as maybe this will shed some light. I receive a compile error expected end sub.

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    XL 2010,2016
    Posts
    11,815

    Re: Specific sheet name macro help

    Yes, you threw one sub inside another sub.

    I was just showing you how to loop through the sheets, if the sheet name = something then do something.

    Here is a more idealized example.

    Don't get caught up in the arrays and confusing stuff.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-08-2019
    Location
    CO
    MS-Off Ver
    Latest
    Posts
    12

    Re: Specific sheet name macro help

    The Array portion is working perfectly in the top section. Its somewhat complicated what that code is doing. Is there just a way to execute what I am looking for with also keeping the top portion?

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    Posts
    2,683

    Re: Specific sheet name macro help

    Maybe explain in a short but sweet manner what you want to accomplish. Be concise.
    All the "Selecting" in your code only slows down execution time and is not required.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    XL 2010,2016
    Posts
    11,815

    Re: Specific sheet name macro help

    Sure,
    Add the additional code to your code and edit to suite your requirements.

  8. #8
    Registered User
    Join Date
    08-08-2019
    Location
    CO
    MS-Off Ver
    Latest
    Posts
    12

    Re: Specific sheet name macro help

    OK, I got all of it working now. Thanks guys for your help!

+ 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