» Sort the worksheets in a workbook using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
Sub SortWorksheets()
' sort worksheets in a workbook in ascending order
Dim sCount As Integer, i As Integer, j As Integer
Application.ScreenUpdating = False
sCount = Worksheets.Count
If sCount = 1 Then Exit Sub
For i = 1 To sCount - 1
For j = i + 1 To sCount
If Worksheets(j).Name < Worksheets(i).Name Then
Worksheets(j).Move Before:=Worksheets(i)
End If
Next j
Next i
End Sub
If you want to sort all the sheets in the workbook, replace worksheets with sheets.
Book Store:
Recommended Books:
- The South Beach Diet: The Delicious, Doctor-Designed, Foolproof Plan for Fast and Healthy Weight Loss
- Writing Excel Macros with VBA, 2nd Edition
- Excel 2002 For Dummies®
- Windows XP for Dummies
- Who Moved My Cheese? An Amazing Way to Deal with Change in Your Work and in Your Life
- What the IRS Doesn't Want You to Know: A Cpa Reveals the Tricks of the Trade
No comments have been submitted.

