+ Reply to Thread
Results 1 to 11 of 11

Exclude some sheets

  1. #1
    Registered User
    Join Date
    04-05-2007
    Location
    Sydney Australia
    Posts
    48

    Exclude some sheets

    Hi All

    I would like to run a macro on all the sheets in a workbook except for two sheets named DataSheet and ListSheet. The remaining sheets are named Sheet1 Sheet2 etc. The number of sheets may vary from 2 through to 20.

    I have searched these forums and found reference to this subject including various examples of code which handles this task.

    Unfortunately i can't seem to adapt any of them to do exactly what i want

    Any assistance would again be very appreciated.

    Thanks

    jeff

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444
    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    04-05-2007
    Location
    Sydney Australia
    Posts
    48
    Hi Dave

    Thanks for your reply.

    Your code works great if there are exactly 20 sheets in the workbook. The number may vary however from 2 up to 20 so i need it to run without specifying exact numbers of sheets. Can you help further??

    Thanks again

    Jeff

  4. #4
    Forum Contributor
    Join Date
    11-23-2005
    Location
    Perth, Australia
    Posts
    218

    Exclude some sheets

    Add something like the following:
    Please Login or Register  to view this content.
    Then change:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    That should do what you need

    Let me know how it goes!

  5. #5
    Registered User
    Join Date
    04-05-2007
    Location
    Sydney Australia
    Posts
    48
    thanks Steel Monkey

    Your suggestions did do as i wanted however the code runs correctly and then i get a subscript out of range error on the highlighed line

    Please Login or Register  to view this content.
    What do you think?

    Thanks

    Jeff

  6. #6
    Forum Contributor
    Join Date
    11-23-2005
    Location
    Perth, Australia
    Posts
    218
    Thta makes sense as it would be trying to select a sheet called "sheetDataList" which isnt there.

    What you would be better off doing is looping through ALL sheets and not setting a number to loop through. Please see the below code which will loop through all sheets and check if the currentsheet is named Datasheet or Listsheet and if if it will go to the next sheet.

    Enter your code on what you want done and it should work fine

    Please Login or Register  to view this content.
    Let me know how you go!

  7. #7
    Registered User
    Join Date
    04-05-2007
    Location
    Sydney Australia
    Posts
    48
    Using that piece of code the action is performed only on the sheet called DataSheet and not on any of the others.

    I think i understand what you are trying to do but it seems to be working in reverse??????

    Jeff

  8. #8
    Forum Contributor
    Join Date
    11-23-2005
    Location
    Perth, Australia
    Posts
    218

    This time for sure

    Ok give this one a go!

    Please Login or Register  to view this content.
    Last edited by Steel Monkey; 05-03-2007 at 12:34 AM.

  9. #9
    Forum Contributor
    Join Date
    11-23-2005
    Location
    Perth, Australia
    Posts
    218

    Silly Silly Steel Monkey

    You can use either of the two examples above but if you use the first one just add wssheet.select and it will work perfectly:


    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-05-2007
    Location
    Sydney Australia
    Posts
    48

    Thumbs up Not so silly!!!

    I certainly don't think you're silly.

    Your code works just great.

    All you guys on this forum are so generous with both your time and your knowledge. One day I hope to know enough to answer some questions myself.

    Thanks

    Jeff

  11. #11
    Forum Contributor
    Join Date
    11-23-2005
    Location
    Perth, Australia
    Posts
    218

    Exclude some sheets

    No worries at all

    Glad I could 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