#1   Report Post  
Posted to microsoft.public.excel.misc
Stan
 
Posts: n/a
Default Sort tabs

Is there a way to sort tabs in the worksheet? I've been manually dragging the
tabs to put them in the alphabetical order, but if someone can advise a way,
that would be great.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Rech
 
Posts: n/a
Default Sort tabs

Chip Pearson has a macro for sorting worksheets.

http://www.cpearson.com/excel/sortws.htm

--
Jim
"Stan" wrote in message
...
| Is there a way to sort tabs in the worksheet? I've been manually dragging
the
| tabs to put them in the alphabetical order, but if someone can advise a
way,
| that would be great.
| Thanks


  #3   Report Post  
Posted to microsoft.public.excel.misc
NickG
 
Posts: n/a
Default Sort tabs


this VBA code should help you achieve what you want.

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



--
NickG
------------------------------------------------------------------------
NickG's Profile: http://www.excelforum.com/member.php...o&userid=33865
View this thread: http://www.excelforum.com/showthread...hreadid=536411

  #4   Report Post  
Posted to microsoft.public.excel.misc
NickG
 
Posts: n/a
Default Sort tabs


this VBA code should help you achieve what you want.

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



--
NickG
------------------------------------------------------------------------
NickG's Profile: http://www.excelforum.com/member.php...o&userid=33865
View this thread: http://www.excelforum.com/showthread...hreadid=536411

  #5   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default Sort tabs

If you're going to take verbatim code from my site, I would
appreciate a reference to the page.
www.cpearson.com/excel/sortws.htm


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"NickG"
wrote in message
...

this VBA code should help you achieve what you want.

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



--
NickG
------------------------------------------------------------------------
NickG's Profile:
http://www.excelforum.com/member.php...o&userid=33865
View this thread:
http://www.excelforum.com/showthread...hreadid=536411



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort tabs in a workbook other than one at a time with move or cop. Hoflinger Excel Worksheet Functions 3 September 17th 06 03:38 AM
Select rows and sort based on type Sarah Excel Discussion (Misc queries) 0 October 11th 05 05:06 PM
sort sheet tabs in Excel JOJO Excel Worksheet Functions 2 May 19th 05 04:36 AM
Can I sort Excel sheet tabs alphabetically? Governors Club Excel Discussion (Misc queries) 1 February 25th 05 07:56 PM
sort tabs in a workbook other than one at a time with move or cop. Hoflinger Excel Worksheet Functions 1 February 2nd 05 04:41 PM


All times are GMT +1. The time now is 08:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"