Consulting

Results 1 to 3 of 3

Thread: Sort Sheets in ascending order

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    54
    Location

    Sort Sheets in ascending order

    Hi,

    I am trying to sort sheets in a workbook in a numerical order.

    Suppose I have 10 sheets namely ; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

    Now when I try to sort them using VBA the result is :-

    1, 10, 2, 3, 4, 5, 6, 7, 8

    ??

    Here's the code i'm using:

    Sub SortWorksheets()
    Dim sCount As Integer, i As Integer, j As Integer
        Application.ScreenUpdating = False
        sCount = Worksheets.Count
        If sCount = 1 Then Exit Sub
        For i = 1 To sCount - 1
            For j = i + 1 To sCount
                If Worksheets(j).Name < Worksheets(i).Name Then
                    Worksheets(j).Move Before:=Worksheets(i)
                End If
            Next j
        Next i
    End Sub

    Any solutions??

    Tried the code from the KB as well.. But getting the same problem..

    Thanks
    Last edited by Aussiebear; 04-25-2023 at 09:49 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •