code for sheet order

dennisli

Well-known Member
Joined
Feb 20, 2004
Messages
1,070
Good morning,
I have some sheets named as year in such format 2000, 2001, 2008, 2007, 2005. I also have some other sheets named in letter such as Total, Payment, or in number but not four digits such as 11, 22, 32.
I need to put all these kinds of sheet with four digit number on the right side of sheet named Total, ranked from the latest year to the oldest year, such as 2008, 2007, 2005, 2001, 2000.
All other sheets should be put on the left of sheet named Total.
Any idea? Thanks lot.
Dennis
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Here is my take:


Code:
Sub movesheets()
    Dim sh, ct, sname, ws
    Sheets("Total").Move after:=Sheets(Sheets.Count)
    Set ws = ThisWorkbook.Sheets.Add
    For Each sh In ThisWorkbook.Sheets
        If sh.Name Like "####" Then
            ws.Range("A1").Offset(ct, 0) = sh.Name
            ct = ct + 1
        End If
    Next sh
    ws.Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    For Each sname In ws.Range("A1:A" & ct)
        Sheets(CStr(sname)).Move after:=Sheets(Sheets.Count)
    Next
    Application.DisplayAlerts = False
    ws.Delete
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,690
Messages
6,056,755
Members
444,889
Latest member
ibbara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top