Code in the attached file can help you.



On Mon, Feb 2, 2009 at 3:45 PM, Alokeshwar Tiwary <
alokeshwar.tiw...@yahoo.com> wrote:

>
> See attached, this might help you.
>
>
> _________________________________________________________________________________________________
> "There are known knowns. These are things we know that we know. There are
> known unknowns. That is to say, there are things that we know we don't know.
> But there are also unknown unknowns. There are things we don't know we don't
> know."
>
>
>  ------------------------------
> *From:* Amanda <propagan...@gmail.com>
> *To:* MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com>
> *Sent:* Monday, 2 February, 2009 10:10:30 AM
> *Subject:* $$Excel-Macros$$ Tab organization in large spreadsheets
>
>
> Hi,
>
> I am going to be working on a spreadsheet which will have a tab for
> every member of staff in my faculty (could be over 100 tabs).
>
> I need to write a Macro that will, when run, sort the tabs into
> alphabetical order (they will be named as 'Last name, First name'). Is
> this possible?
>
> Also, it would be great if, when we re-run the macro as the semester
> progresses and more people are added, we can re-run the macro and it
> will re-read all the tabs and include the new tabs in the re-ordering.
>
> Thanks,
> Amanda
>
> ------------------------------
> Add more friends to your messenger and enjoy! Invite them 
> now.<http://in.rd.yahoo.com/tagline_messenger_6/*http://messenger.yahoo.com/invite/>
> >
>
>

--~--~---------~--~----~------------~-------~--~----~
Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To post to this group, send email to excel-macros@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/excel-macros?hl=en

Visit & Join Our Orkut Community at 
http://www.orkut.com/Community.aspx?cmm=22913620

To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com

To see the Daily Excel Tips, Go to:
http://exceldailytip.blogspot.com
 
If you find any spam message in the group, please send an email to Ayush @ 
jainayus...@gmail.com
-~----------~----~----~----~------~----~------~--~---

Option Explicit 
 
Sub SortWorksheets() 
     
    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 
         
         'Change the 1 to the worksheet you want sorted first
        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 

Reply via email to