ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I alphabetize sheet tabs within a worksheet? (https://www.excelbanter.com/excel-discussion-misc-queries/182214-how-do-i-alphabetize-sheet-tabs-within-worksheet.html)

michelle

How do I alphabetize sheet tabs within a worksheet?
 


Ron Rosenfeld

How do I alphabetize sheet tabs within a worksheet?
 
On Wed, 2 Apr 2008 08:16:03 -0700, Michelle
wrote:

You need a Macro to do that.

Put this into a regular module:

=================
Option Explicit
Sub SortWorksheets()
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean

SortDescending = False

If ActiveWindow.SelectedSheets.Count = 1 Then
FirstWSToSort = 1
LastWSToSort = Worksheets.Count
Else
With ActiveWindow.SelectedSheets
For N = 2 To .Count
If .Item(N - 1).Index < .Item(N).Index - 1 Then
MsgBox "You cannot sort non-adjacent sheets"
Exit Sub
End If
Next N
FirstWSToSort = .Item(1).Index
LastWSToSort = .Item(.Count).Index
End With
End If

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
========================
--ron

Dave Peterson

How do I alphabetize sheet tabs within a worksheet?
 
Check your other post, too.

Michelle wrote:

--

Dave Peterson

Ron Rosenfeld

How do I alphabetize sheet tabs within a worksheet?
 
On Wed, 02 Apr 2008 11:44:20 -0400, Ron Rosenfeld
wrote:

On Wed, 2 Apr 2008 08:16:03 -0700, Michelle
wrote:

You need a Macro to do that.

Put this into a regular module:


By the way, I did not write this macro -- but I cannot recall where I found it.
--ron


All times are GMT +1. The time now is 12:37 PM.

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