+ Reply to Thread
Results 1 to 4 of 4

Excluding certain worksheets from loop macro

  1. #1
    Registered User
    Join Date
    02-27-2015
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    18

    Excluding certain worksheets from loop macro

    Hi All,
    I am running a macro loop on several worksheets in a workbook and it works, but I would like to exclude worksheets that have "14" or "15" in their name (for example Jan14, Feb14, Jan15). How can I do this? The code below doesn`t work, the loop still runs on those worksheets with "14" or "15" in their name.
    (I have just put the code I am looping as "`loop Code" as that works fine, no need to look into it.)
    Could someone help me with this? Cheers, A.

    Please Login or Register  to view this content.
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,091

    Re: Excluding certain worksheets from loop macro

    Please Login or Register  to view this content.

    Note: you don't need to activate a sheet to act upon it.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-27-2015
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    18

    Re: Excluding certain worksheets from loop macro

    Thank a lot, TMS! It works, even though I left out `Debug.Print ws.Name`...I don`t understand why I would need this..?
    Also, you said that I don`t need to activate a sheet to act upon it.....but you yourself included ws.Activate in your code...why is that?
    Anyway, thank you!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,091

    Re: Excluding certain worksheets from loop macro

    You're welcome. Thanks for the rep.

    Debug.Print ws.Name
    you don't need it. I just put it in to test the loop.

    I was just making the point, not correcting your code. But, in this simple example, you could take it out. It would be much faster and it wouldn't give you a headache rotating through the worksheets.




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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] Have a loop macro loop for all visible worksheets
    By Graeme-Black in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-22-2014, 11:01 AM
  2. Loop Macro Excluding 1 specific sheet
    By noorie007 in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 07-16-2012, 09:54 AM
  3. macro loop through worksheets
    By asdzxc in forum Excel General
    Replies: 4
    Last Post: 05-09-2012, 03:24 AM
  4. Replies: 9
    Last Post: 12-03-2010, 04:37 AM
  5. VBA Loop (?) - macro to run through 33 worksheets!
    By lealea1982 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2010, 07:20 AM

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