In this article, we will learn sorting sheets in ascending order through VBA in Microsoft Excel 2010.
While working on multiple sheets, you find that sheets are not properly arranged. You want to create a macro quickly which will automatically sort the sheet in ascending order whenever macro is run.
To sort the sheets in ascending order, follow the below mentioned steps:
Dim i As Integer, n As Integer, SheetsCounter As Integer
If ActiveWorkbook Is Nothing Then Exit Sub
If ActiveWorkbook.ProtectStructure Then
MsgBox ActiveWorkbook.Name & ” is protected”, vbCritical, “Sort Sheets”
If MsgBox(“Sort Sheets?”, vbQuestion + vbYesNo) <> vbYes Then Exit Sub
Application.EnableCancelKey = xlDisabled
SheetsCounter = Sheets.Count
For i = 2 To SheetsCounter
For n = 1 To SheetsCounter
If Sheets(n).Name > Sheets(i).Name Then
Alternatively, press Alt+F11 and return to Excel, assign the macro to any Excel object as a button or icon, or press Alt+F8 to select the macro, and then click Run.
You will find that the sheets are arranged in an alphanumeric order.
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.