0
votes

I'm new to VBA and couldn't find any solution for my little problem in any threads for using VBA sorting.

A software is writing data into Excel and it creates sheets from 1-30. My problem is, those sheets arent in an order.

With every sorting I tried so far, I always get the result: sheet1, sheet10, sheet11...sheet19, sheet2, sheet20, sheet21,...sheet29, sheet3, sheet30, sheet4, sheet5, sheet6,...

I'm looking for a solution to get those sheets in order like: sheet1, sheet2,sheet3...sheet29, sheet30.

My only idea now is to create a new sheet by Macro, create a list (sheet1...sheet30) and let those sheets get sorted by the list.

But Im pretty sure there is a smarter way to solve the problem.

Thx in advance for any suggestions.

1

1 Answers

0
votes

As long as your sheets are names like "Sheet1" , Sheet2", .... then:

Sub RestoreOrder()
    Dim N As Long, i As Long
    N = Sheets.Count
    For i = 1 To N
        Sheets("Sheet" & i).Move after:=Sheets(N)
    Next i
End Sub

appears to work.