Advertisement
NonplayerCharacter

Excel | Sort sheets alphabetically

Mar 7th, 2023 (edited)
1,707
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '
  2. ' Alt+F11, Insert > Module, paste, hit F5 (instructions from https://www.extendoffice.com/documents/excel/629-excel-sort-sheets.html)
  3. ' Code from https://learn.microsoft.com/en-us/office/vba/excel/concepts/workbooks-and-worksheets/sort-worksheets-alphanumerically-by-name
  4. '
  5. Sub SortSheetsTabName()
  6.     Application.ScreenUpdating = False
  7.     Dim iSheets%, i%, j%
  8.     iSheets = Sheets.Count
  9.     For i = 1 To iSheets - 1
  10.         For j = i + 1 To iSheets
  11.             If Sheets(j).Name < Sheets(i).Name Then
  12.                 Sheets(j).Move before:=Sheets(i)
  13.             End If
  14.         Next j
  15.     Next i
  16.     Application.ScreenUpdating = True
  17. End Sub
  18.  
Tags: excel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement