ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting Worksheets in Alphabetical Order (Left to Right) (https://www.excelbanter.com/excel-programming/300831-sorting-worksheets-alphabetical-order-left-right.html)

Jako[_14_]

Sorting Worksheets in Alphabetical Order (Left to Right)
 
Can anyone please suggest a way to organize the Worksheet Tabs i
alphabetical order running from left to right.

Thanks in Advance

--
Message posted from http://www.ExcelForum.com


JMay

Sorting Worksheets in Alphabetical Order (Left to Right)
 
In a standard module put:

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

HTH - (Hope this helps)
JMay


"Jako " wrote in message
...
Can anyone please suggest a way to organize the Worksheet Tabs in
alphabetical order running from left to right.

Thanks in Advance.


---
Message posted from http://www.ExcelForum.com/




Doug Glancy

Sorting Worksheets in Alphabetical Order (Left to Right)
 
Jako,

See this page at Chip Pearson's site:

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

hth,

Doug Glancy

"Jako " wrote in message
...
Can anyone please suggest a way to organize the Worksheet Tabs in
alphabetical order running from left to right.

Thanks in Advance.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 10:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com