Results 1 to 3 of 3

Thread: How to Sort Excel Worksheets Alphabetically

  1. #1
    Join Date
    Dec 2008
    Posts
    135

    How to Sort Excel Worksheets Alphabetically

    Hi friends,

    I want to sort my employees name in worksheets should be displayed in alphabetically order. I try to check order and sort in a workbook_sheetselectionchange with macro, but I'm not sure where to put it, or how to write the code. Can anyone help me out to write code for it.

  2. #2
    Join Date
    Jan 2009
    Posts
    150

    Re: How to Sort Excel Worksheets Alphabetically

    Try to use the following code i hope it will work for you.

    Code:
    Sub SortWorksheets()
    Dim N As Integer
    Dim M As Integer
    Dim FirstWSToSort As Integer
    Dim LastWSToSort As Integer
    Dim SortDescending As Boolean
    Dim AscDesc
    
    AscDesc = MsgBox(prompt:="Sort worksheets in ascending order?", _
    Title:="Sort Order", _
    Buttons:=vbYesNoCancel)
    If AscDesc = vbYes Then
    SortDescending = False
    ElseIf AscDesc = vbNo Then
    SortDescending = True
    Else
    Exit Sub
    End If
    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

  3. #3
    Join Date
    Oct 2011
    Posts
    1

    Happy Re: How to Sort Excel Worksheets Alphabetically



    Well, what the wonderful scripts are!

    But I am not a programmer and will be confused by the long and complicated scripts. Now, about the sort worksheets issue, I would like to provide a most somple way to do it. The application I found is Kutools for Excel , which is an excel add-ins collection to free from time consuming and repetitive excel work.Very small size. After installing the app, it adds a "Kutools" tab in the ribbon, and then just clcik "worksheet manager" and choose "sort worksheets", then your sheets are sorted in alphabetical or numeric order. Is that so easy? I still keep using the app and find more useful functions in it.

Similar Threads

  1. Replies: 9
    Last Post: 09-01-2012, 11:21 AM
  2. Replies: 8
    Last Post: 04-12-2011, 11:24 AM
  3. Replies: 6
    Last Post: 05-10-2010, 12:56 AM
  4. Sort list alphabetically in java
    By New ID in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 12:38 AM
  5. What is Workbook and Worksheets in Excel
    By Xylina in forum Windows Software
    Replies: 3
    Last Post: 06-06-2009, 07:13 PM

Tags for this Thread

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
  •  
Page generated in 1,674,892,910.60312 seconds with 17 queries