XLA routines: EE_RearrangeSheetsAlphabetic

Nick's picture
EE_RearrangeSheetsAlphabetic is useful to use at the end of your procedure when you have created sheets all over the place and want them rearraged alphabetically.
Sub EE_RearrangeSheetsAlphabetic(Optional SortDescending As Boolean = False)
'> - takes a boolean to tell whether ascending or descending
'> - rearranges sheets
    Dim intLoopFull     As Integer
    Dim intLoopInner    As Integer
    Dim wbk             As Workbook
'http://excelexperts.com/xla-routines-eerearrangesheetsalphabetic
    
    Set wbk = ThisWorkbook
 
    For intLoopInner = 1 To wbk.Worksheets.Count
        For intLoopFull = intLoopInner To wbk.Worksheets.Count
            If SortDescending = True Then
                If UCase(wbk.Worksheets(intLoopFull).Name) > UCase(wbk.Worksheets(intLoopInner).Name) Then
                    wbk.Worksheets(intLoopFull).Move Before:=wbk.Worksheets(intLoopInner)
                End If
            Else
                If UCase(wbk.Worksheets(intLoopFull).Name) < UCase(wbk.Worksheets(intLoopInner).Name) Then
                    wbk.Worksheets(intLoopFull).Move Before:=wbk.Worksheets(intLoopInner)
                End If
            End If
        Next intLoopFull
    Next intLoopInner
 
    Set wbk = Nothing
End Sub