ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort worksheets (https://www.excelbanter.com/excel-programming/373479-sort-worksheets.html)

donbowyer

Sort worksheets
 
I have a workbook with 20 named sheets.
How can I programmatically arrange them in alphabetical order?
--
donwb

Gary Keramidas

Sort worksheets
 
try chip pearson's code:

Sub AlphaSortWorksheets()

Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean

SortDescending = False
FirstWSToSort = 1
LastWSToSort = Worksheets.Count

For M = FirstWSToSort To LastWSToSort
For N = M To LastWSToSort
If SortDescending = True Then
If UCase(Worksheets(N).Name) _
UCase(Worksheets(M).Name) Then
Worksheets(N).Move befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < _
UCase(Worksheets(M).Name) Then
Worksheets(N).Move befo=Worksheets(M)
End If
End If
Next N
Next M

End Sub

--


Gary


"donbowyer" wrote in message
...
I have a workbook with 20 named sheets.
How can I programmatically arrange them in alphabetical order?
--
donwb




donbowyer

Sort worksheets
 
Thangs Gary worked fine
--
donwb


"Gary Keramidas" wrote:

try chip pearson's code:

Sub AlphaSortWorksheets()

Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean

SortDescending = False
FirstWSToSort = 1
LastWSToSort = Worksheets.Count

For M = FirstWSToSort To LastWSToSort
For N = M To LastWSToSort
If SortDescending = True Then
If UCase(Worksheets(N).Name) _
UCase(Worksheets(M).Name) Then
Worksheets(N).Move befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < _
UCase(Worksheets(M).Name) Then
Worksheets(N).Move befo=Worksheets(M)
End If
End If
Next N
Next M

End Sub

--


Gary


"donbowyer" wrote in message
...
I have a workbook with 20 named sheets.
How can I programmatically arrange them in alphabetical order?
--
donwb






All times are GMT +1. The time now is 11:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com