Code:
Sub SortSelectedWorksheets()
'---------------------
MTxt = MsgBox("- Sort Selected Worksheet(s) -" & vbNewLine & "---------------------" & vbNewLine & _
"Yes : Ascendingly" & vbNewLine & _
"No : Descendingly", vbYesNoCancel)
'---------------------
SheetCount = ActiveWindow.SelectedSheets.Count
'---------------------
With ActiveWindow
Select Case (MTxt)
' ________________ [ sort ascendingly ] ________________
Case (vbYes):
For i = 1 To SheetCount - 1
For j = i + 1 To SheetCount
If (.SelectedSheets(j).Name < .SelectedSheets(i).Name) Then
.SelectedSheets(j).Move before:=.SelectedSheets(i)
End If
Next
Next
' ________________ [ sort descendingly ] ________________
Case (vbNo):
For i = 1 To SheetCount - 1
For j = i + 1 To SheetCount
If (.SelectedSheets(j).Name > .SelectedSheets(i).Name) Then
.SelectedSheets(j).Move before:=.SelectedSheets(i)
End If
Next
Next
End Select
'---------------------
End With
End Sub
I got an error for the above in sorting 5 selected worksheets.
But I am just unsure which part goes wrong.
Any hint?
Thanks a lot!
Last edited: