Home |
Search |
Today's Posts |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
Does anyone know if there is a way to sort Excel worksheets?
Give this a shot: (In a standard module)
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 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 Befo=Worksheets(M) End If Else If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name) Then Worksheets(N).Move Befo=Worksheets(M) End If End If Next N Next M End Sub "Steph" wrote in message ... I have created a number of Excel S/sheets in one document - but would like to alphabeticise them... is this possible? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to sort or aphabetize worksheets in Excel? | Excel Discussion (Misc queries) | |||
Can I automatically sort worksheets in excel? | Excel Worksheet Functions | |||
sellect and sort worksheets by name in excel | Excel Discussion (Misc queries) | |||
How do I sort data into 2 worksheets in excel vba? | Excel Worksheet Functions | |||
how can i sort excel worksheets in alphabetical order? | Excel Worksheet Functions |