+ Reply to Thread
Results 1 to 4 of 4

How to Sort/Alphabetize Worksheets by Name

Hybrid View

Guest How to Sort/Alphabetize... 05-16-2005, 06:06 PM
Guest Re: How to Sort/Alphabetize... 05-16-2005, 06:06 PM
Guest RE: How to Sort/Alphabetize... 05-16-2005, 06:06 PM
Guest RE: How to Sort/Alphabetize... 05-16-2005, 11:06 PM
  1. #1
    Chaplain Doug
    Guest

    How to Sort/Alphabetize Worksheets by Name

    Excel 2003. I am programmatically creating a master workbook from multiple
    workbooks. When I am done I would like to arrange the worksheets in the
    master workbook in alphabetical order, according to the worsheet names. How
    may this be done? Thanks.
    --
    Dr. Doug Pruiett
    Good News Jail & Prison Ministry
    www.goodnewsjail.org

  2. #2
    JE McGimpsey
    Guest

    Re: How to Sort/Alphabetize Worksheets by Name

    one way:

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


    In article <2D5D86A1-383A-41ED-BB74-0582A53F4502@microsoft.com>,
    "Chaplain Doug" <ChaplainDoug@discussions.microsoft.com> wrote:

    > Excel 2003. I am programmatically creating a master workbook from multiple
    > workbooks. When I am done I would like to arrange the worksheets in the
    > master workbook in alphabetical order, according to the worsheet names. How
    > may this be done? Thanks.


  3. #3
    Jim Thomlinson
    Guest

    RE: How to Sort/Alphabetize Worksheets by Name

    Public Sub SortWorksheets()
    On Error Resume Next
    Dim N As Integer
    Dim M As Integer
    Dim FirstWSToSort As Integer
    Dim LastWSToSort As Integer
    Dim SortDescending As Boolean

    Application.ScreenUpdating = False
    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

    Application.ScreenUpdating = False
    End Sub

    HTH
    "Chaplain Doug" wrote:

    > Excel 2003. I am programmatically creating a master workbook from multiple
    > workbooks. When I am done I would like to arrange the worksheets in the
    > master workbook in alphabetical order, according to the worsheet names. How
    > may this be done? Thanks.
    > --
    > Dr. Doug Pruiett
    > Good News Jail & Prison Ministry
    > www.goodnewsjail.org


  4. #4
    Chaplain Doug
    Guest

    RE: How to Sort/Alphabetize Worksheets by Name

    This is what I used to accomplish the sheet sort:

    'Now sort the sheets in the master workbook by name
    'Use a bubble sort
    With WbNew
    JFound = True: J = 0
    While JFound = True
    DoEvents
    JFound = False
    For I = 1 To .Sheets.Count - 1
    DoEvents
    If .Worksheets(I + 1).Name < .Worksheets(I).Name Then
    .Worksheets(I + 1).Move before:=.Worksheets(I)
    JFound = True
    End If
    Next I
    J = J + 1
    Wend
    End With

    Thanks for the help!

    "Chaplain Doug" wrote:

    > Excel 2003. I am programmatically creating a master workbook from multiple
    > workbooks. When I am done I would like to arrange the worksheets in the
    > master workbook in alphabetical order, according to the worsheet names. How
    > may this be done? Thanks.
    > --
    > Dr. Doug Pruiett
    > Good News Jail & Prison Ministry
    > www.goodnewsjail.org


+ 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