Dim wb As Workbook, ws As Worksheet, cs As Worksheet, cell As Range
Set wb = ActiveWorkbook
Set ws = ActiveSheet
For Each cs In wb.Sheets
If cs.Name <> ws.Name Then
ws.Range("A65535").End(xlUp).Offset(1, 0).Value = cs.Name
End If
Next cs
ws.Range("A1", ws.Range("A65535").End(xlUp)).Sort ws.Range("A2"), xlDescending
For Each cell In ws.Range("A2", ws.Range("A65535").End(xlUp))
wb.Sheets(cell.Value).Move , Sheets(1)
Next cell
ws.Range("A1", ws.Range("A65535").End(xlUp)).ClearContents
ws.Activate
Just stumbled on this post, and I know it already has a solution, but thought I would post mine as well. I use the build in excel sort capabilities to sort by name, so I don't need to do an array sort.
Code:Dim wb As Workbook, ws As Worksheet, cs As Worksheet, cell As Range Set wb = ActiveWorkbook Set ws = ActiveSheet For Each cs In wb.Sheets If cs.Name <> ws.Name Then ws.Range("A65535").End(xlUp).Offset(1, 0).Value = cs.Name End If Next cs ws.Range("A1", ws.Range("A65535").End(xlUp)).Sort ws.Range("A2"), xlDescending For Each cell In ws.Range("A2", ws.Range("A65535").End(xlUp)) wb.Sheets(cell.Value).Move , Sheets(1) Next cell ws.Range("A1", ws.Range("A65535").End(xlUp)).ClearContents ws.Activate
Just add a button to a blank worksheet you have inserted(This one will not be sorted) and add the code to the button. Exit design mode and press the button.
HTH
Cal
Private Sub CommandButton1_Click()
Dim wb As Workbook, ws As Worksheet, cs As Worksheet, cell As Range
Set wb = ActiveWorkbook
Set ws = ActiveSheet
For Each cs In wb.Sheets
If cs.Name <> ws.Name Then
ws.Range("A65535").End(xlUp).Offset(1, 0).Value = "'" & cs.Name
End If
Next cs
ws.Range("A1", ws.Range("A65535").End(xlUp)).Sort ws.Range("A2"), xlDescending
For Each cell In ws.Range("A2", ws.Range("A65535").End(xlUp))
wb.Sheets(cell.Text).Move , Sheets(1)
Next cell
ws.Range("A1", ws.Range("A65535").End(xlUp)).ClearContents
ws.Activate
End Sub