Thread: Dave and/or Tom
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Dave and/or Tom

You can try this:

Sub SortWorksheets()

Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
Dim sN as String, sM as String
Dim MaxLen as Long

SortDescending = False
FirstWSToSort = 1
LastWSToSort = Worksheets.Count
For M = FirstWSToSort To LastWSToSort
If Len(Worksheets(M).Name) MaxLen Then
MaxLen = Len(Worksheets(M).Name)
End If
Next

For M = FirstWSToSort To LastWSToSort - 1
For N = M + 1 To LastWSToSort
sN = Right(Space(MaxLen) & _
UCase(Worksheets(N).Name), MaxLen)
sM = Right(Space(MaxLen) & _
UCase(Worksheets(M).Name), MaxLen)
If SortDescending = True Then
If sN sM Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If sN < sM Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M

End Sub

--
Regards,
Tom Ogilvy



"jnf40" wrote in message
...
Could you check my post named Sorting Worksheets Numerically please