Forum Discussion
Gretc1865
Feb 20, 2022Copper Contributor
A to Z format
I can't figure out how to sort my spreadsheet alphabetically...not just by column or row, but the whole spreadsheet. I want to have it listed alphabetically and it would also help me eliminate duplic...
Feb 20, 2022
This post to help you to sort your sheets
I believe you will need to use VBA, open the VBA editor by pressing Alt+F11 --> from Insert menu -> click on Module.
Copy the below code and save the file.
Now, to sort the sheets, open the Macro window by pressing Alt+F8, then run the macro with the name Sort_Active_Book
Sub Sort_Active_Book()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
'
' Prompt the user as which direction they wish to
' sort the worksheets.
'
iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
& "Clicking No will sort in Descending Order", _
vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
For i = 1 To Sheets.Count
For j = 1 To Sheets.Count - 1
'
' If the answer is Yes, then sort in ascending order.
'
If iAnswer = vbYes Then
If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
'
' If the answer is No, then sort in descending order.
'
ElseIf iAnswer = vbNo Then
If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
End If
Next j
Next i
End Sub