+ Reply to Thread
Results 1 to 5 of 5

Sort worksheet tabs (with exclusions)

  1. #1
    Registered User
    Join Date
    02-10-2011
    Location
    Canada
    MS-Off Ver
    Excel 2019 / MS365
    Posts
    55

    Sort worksheet tabs (with exclusions)

    I need to group / sort worksheet tabs alphabetically. The one area which I cannot solve is how to group & sort only tab names which include a specific string. The workbooks will have varying numbers of sheet tabs. I need to move all the sheet tabs where the tab name begins with "INV". This string is suffixed with incremental numbers.
    • The sheet tabs which do not contain the text string should be excluded from the sort.
    • There may also be hidden sheets, so the code will need to run only on the visible sheets.

    This is an example of a possible tab order before sorting:
    Tabs Unsorted.bmp

    After running the code, it should be sorted as follows:
    Tabs Sorted.bmp

    The attached workbook contains a code module, but it does not work when sorting only specific tabs and ignoring the others. I plan to include this code in the 'Deactivate' event in the Sheets("Template") module.

    Thank you in advance, for your response.
    Attached Files Attached Files
    Last edited by pinebush; 12-17-2021 at 02:51 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: Sort worksheet tabs (with exclusions)

    Sheets("INV_1").Move Before:=Sheets(5)
    Sheets("INV_2").Move Before:=Sheets(6)
    Sheets("INV_3").Move Before:=Sheets(7)

    .... ETC.

    You'd have to write this line of code for every new "(INV_#)" sheet

  3. #3
    Registered User
    Join Date
    02-10-2011
    Location
    Canada
    MS-Off Ver
    Excel 2019 / MS365
    Posts
    55

    Re: Sort worksheet tabs (with exclusions)

    As mentioned, each workbook will have varying numbers of sheet tabs. I also will not know the number of sheet tabs which meet the criteria. This method seems to add complexity - I would find it easier to manually drag the sheets into position.

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Sort worksheet tabs (with exclusions)

    Try this

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-10-2011
    Location
    Canada
    MS-Off Ver
    Excel 2019 / MS365
    Posts
    55

    Re: Sort worksheet tabs (with exclusions)

    Thank you JEC for your solution. I discovered that it fails when there are worksheets which are xlSheetVeryHidden. I modified 2 lines of code, which seem to handle every possibility.
    Instead of
    Please Login or Register  to view this content.
    , I am able to use
    Please Login or Register  to view this content.
    I appreciate your prompt response with a working solution.

+ 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. How to add new tabs and have sort macros work on new tabs correctly
    By Vicious00013 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-13-2016, 05:43 AM
  2. Macro to sort tabs in a worksheet
    By AnalystMH in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-07-2016, 12:32 PM
  3. [SOLVED] Renaming Worksheet Tabs with Tabs Existing Name + Today's Date
    By longbow007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-26-2016, 09:51 PM
  4. Replies: 6
    Last Post: 02-01-2012, 05:29 PM
  5. Rename worksheet tabs and sheets to match tabs via button
    By timgavin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-31-2011, 06:12 PM
  6. [SOLVED] Sort the Tabs
    By A-Design in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-13-2005, 07:05 PM
  7. Re-Sort Worksheet tabs
    By Campbti in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-10-2005, 02:06 PM

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