+ Reply to Thread
Results 1 to 5 of 5

Sorting the order of sheets by the name

  1. #1
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    183

    Sorting the order of sheets by the name

    Hi

    Is there a way to sort the order of the sheet, depending on the name of the sheets?

    i.e.


    I have several workbooks with names like "Sch 13", "Sch 8A" and "Sch 8B".
    I would like a way to sort these by name or the number they contain.


    Thanks

  2. #2
    Norman Jones
    Guest

    Re: Sorting the order of sheets by the name

    Hi Ctech,

    Try Chip Pearson's procedure:

    '==============>>
    Sub SortWorksheets()
    'Chip Pearson

    Dim N As Integer
    Dim M As Integer
    Dim FirstWSToSort As Integer
    Dim LastWSToSort As Integer
    Dim SortDescending As Boolean

    SortDescending = False

    If ActiveWindow.SelectedSheets.Count = 1 Then
    FirstWSToSort = 1
    LastWSToSort = Worksheets.Count
    Else
    With ActiveWindow.SelectedSheets
    For N = 2 To .Count
    If .Item(N - 1).Index <> .Item(N).Index - 1 Then
    MsgBox "You cannot sort non-adjacent sheets"
    Exit Sub
    End If
    Next N
    FirstWSToSort = .Item(1).Index
    LastWSToSort = .Item(.Count).Index
    End With
    End If

    For M = FirstWSToSort To LastWSToSort
    For N = M To LastWSToSort
    If SortDescending = True Then
    If UCase(Worksheets(N).Name) > _
    UCase(Worksheets(M).Name) Then
    Worksheets(N).Move Before:=Worksheets(M)
    End If
    Else
    If UCase(Worksheets(N).Name) < _
    UCase(Worksheets(M).Name) Then
    Worksheets(N).Move Before:=Worksheets(M)
    End If
    End If
    Next N
    Next M

    End Sub
    '<<==============



    --

    ---
    Regards,
    Norman



    "Ctech" <Ctech.1z1yfy_1132921802.7575@excelforum-nospam.com> wrote in
    message news:Ctech.1z1yfy_1132921802.7575@excelforum-nospam.com...
    >
    > Hi
    >
    > Is there a way to sort the order of the sheet, depending on the name of
    > the sheets?
    >
    > i.e.
    >
    >
    > I have several workbooks with names like "Sch 13", "Sch 8A" and "Sch
    > 8B".
    > I would like a way to sort these by name or the number they contain.
    >
    >
    > Thanks
    >
    >
    > --
    > Ctech
    > ------------------------------------------------------------------------
    > Ctech's Profile:
    > http://www.excelforum.com/member.php...o&userid=27745
    > View this thread: http://www.excelforum.com/showthread...hreadid=488136
    >




  3. #3
    Norman Jones
    Guest

    Re: Sorting the order of sheets by the name

    Hi Ctech,

    I should have additionally suggested that you visit Chip Pearson's Sorting
    Worksheets page for additional information and material.

    ---
    Regards,
    Norman

    "Ctech" <Ctech.1z1yfy_1132921802.7575@excelforum-nospam.com> wrote in
    message news:Ctech.1z1yfy_1132921802.7575@excelforum-nospam.com...
    >
    > Hi
    >
    > Is there a way to sort the order of the sheet, depending on the name of
    > the sheets?
    >
    > i.e.
    >
    >
    > I have several workbooks with names like "Sch 13", "Sch 8A" and "Sch
    > 8B".
    > I would like a way to sort these by name or the number they contain.
    >
    >
    > Thanks
    >
    >
    > --
    > Ctech
    > ------------------------------------------------------------------------
    > Ctech's Profile:
    > http://www.excelforum.com/member.php...o&userid=27745
    > View this thread: http://www.excelforum.com/showthread...hreadid=488136
    >




  4. #4
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    183
    Do you have a link?

  5. #5
    Norman Jones
    Guest

    Re: Sorting the order of sheets by the name

    Hi Ctech,

    My apologies - I noticed the missing link and was sure that I included it in
    a follow-up post.

    The link is:

    http://www.cpearson.com/excel/sortws.htm

    ---
    Regards,
    Norman



    "Ctech" <Ctech.1z24p0_1132929908.8295@excelforum-nospam.com> wrote in
    message news:Ctech.1z24p0_1132929908.8295@excelforum-nospam.com...
    >
    > Do you have a link?
    >
    >
    > --
    > Ctech
    > ------------------------------------------------------------------------
    > Ctech's Profile:
    > http://www.excelforum.com/member.php...o&userid=27745
    > View this thread: http://www.excelforum.com/showthread...hreadid=488136
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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