View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Shailesh Shah[_2_] Shailesh Shah[_2_] is offline
external usenet poster
 
Posts: 114
Default Worksheets in alphabetical order


Hi Mark,

For sorting sheet tab copy below code to your standard module & run
macro sortsheet.

---------------------------------------------------
Sub Sortsheet()
Quicksortsheets ' without arguments for ascending
'Quicksortsheets "D" ' with arguments for descending
end sub

Sub QuickSortSheets(Optional SortOrder)
Dim i As Long
Dim j As Long
Dim SheetsCount As Long
Dim FirstSheet As String
Dim NextSheet As String
Dim LValue As String
Dim HValue As String
Dim VTemp As String
Application.ScreenUpdating = 0
SheetsCount = Worksheets.Count
For i = 1 To SheetsCount \ 2
FirstSheet = Worksheets(i).Name
LValue = FirstSheet
HValue = FirstSheet
For j = i To SheetsCount - 1
NextSheet = Worksheets(j + 1).Name
If LValue NextSheet Then LValue = NextSheet
If HValue < NextSheet Then HValue = NextSheet
Next
If IsMissing(SortOrder) Then
Else
VTemp = LValue
LValue = HValue
HValue = VTemp
End If
If LValue < FirstSheet Then Worksheets
(LValue).Move befo=Worksheets(i)
If HValue < Worksheets(SheetsCount).Name Then
Worksheets(HValue).Move after:=Worksheets(SheetsCount)
SheetsCount = SheetsCount - 1
Next
Application.ScreenUpdating = 1
End Sub



You can also see below sites

www.cpearson.com/excel/sortws.htm

http://www.mvps.org/dmcritchie/excel...#sortallsheets


Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!