Sort worksheet tabs by custom list

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Sort worksheet tabs by custom list

Post by gailb »

I see all sorts of VBA procedure to sort worksheet tabs in alphabetical order, but what if I want to sort by a custom list.

In this workbook, there are 66 tabs I'd like to sort and the list is in Sheet1 Range("D5:D70")

There are 5 tabs before the 66 tabs begin, so the first tab begins in the 6th tab index number

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort worksheet tabs by custom list

Post by HansV »

Code: Select all

Sub SortSheets()
    Dim s As Variant
    Dim i As Long
    Application.ScreenUpdating = False
    s = Worksheets(1).Range("D5:D14").Value
    For i = 1 To UBound(s, 1)
        Worksheets(CStr(s(i, 1))).Move Before:=Worksheets(i + 5)
    Next i
    Application.ScreenUpdating = True
End Sub
Best wishes,
Hans

gailb
3StarLounger
Posts: 254
Joined: 09 May 2020, 14:00

Re: Sort worksheet tabs by custom list

Post by gailb »

Absolutely perfect and thank you Hans. Happy Holidays!

User avatar
HansV
Administrator
Posts: 78568
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort worksheet tabs by custom list

Post by HansV »

Happy Holidays to you (and all members and visitors of Eileen's Lounge) too!
Best wishes,
Hans