ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheets in alphabetical order (https://www.excelbanter.com/excel-programming/283831-worksheets-alphabetical-order.html)

mark

Worksheets in alphabetical order
 
I am using Excel 97.

I want to sort worksheets in a workbook so that they are
in alphabetical order.

Can anyone asist me with some code?

Thanks


Mark

Andy Brown

Worksheets in alphabetical order
 
Sub SortALLSheets()
'sort sheets within a workbook in Excel 7 -- Bill Manville
'modified to sort all sheets instead of just worksheets
Dim iSheet As Integer, iBefore As Integer
For iSheet = 1 To ActiveWorkbook.Sheets.Count
Sheets(iSheet).Visible = True
For iBefore = 1 To iSheet - 1
If UCase(Sheets(iBefore).Name) UCase(Sheets(iSheet).Name) Then
ActiveWorkbook.Sheets(iSheet).Move
Befo=ActiveWorkbook.Sheets(iBefore)
Exit For
End If
Next iBefore
Next iSheet
End Sub

Rgds,
Andy


On the stereo this week ; Albinoni, Samuel Barber, Nirvana, Sinead O'Connor



Shailesh Shah[_2_]

Worksheets in alphabetical order
 

Hi Mark,

For sorting sheet tab copy below code to your standard module & run
macro sortsheet.

---------------------------------------------------
Sub Sortsheet()
Quicksortsheets ' without arguments for ascending
'Quicksortsheets "D" ' with arguments for descending
end sub

Sub QuickSortSheets(Optional SortOrder)
Dim i As Long
Dim j As Long
Dim SheetsCount As Long
Dim FirstSheet As String
Dim NextSheet As String
Dim LValue As String
Dim HValue As String
Dim VTemp As String
Application.ScreenUpdating = 0
SheetsCount = Worksheets.Count
For i = 1 To SheetsCount \ 2
FirstSheet = Worksheets(i).Name
LValue = FirstSheet
HValue = FirstSheet
For j = i To SheetsCount - 1
NextSheet = Worksheets(j + 1).Name
If LValue NextSheet Then LValue = NextSheet
If HValue < NextSheet Then HValue = NextSheet
Next
If IsMissing(SortOrder) Then
Else
VTemp = LValue
LValue = HValue
HValue = VTemp
End If
If LValue < FirstSheet Then Worksheets
(LValue).Move befo=Worksheets(i)
If HValue < Worksheets(SheetsCount).Name Then
Worksheets(HValue).Move after:=Worksheets(SheetsCount)
SheetsCount = SheetsCount - 1
Next
Application.ScreenUpdating = 1
End Sub



You can also see below sites

www.cpearson.com/excel/sortws.htm

http://www.mvps.org/dmcritchie/excel...#sortallsheets


Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Colo

Worksheets in alphabetical order
 
Hi Mark,

Here is a simple code I wrote. Please try this.

Sub WorksheetSort()
Dim intC1 As Long, intC2 As Integer
For intC1 = 1 To Sheets.Count
For intC2 = 1 To Sheets.Count - 1
If Sheets(intC2).Name Sheets(intC2 + 1).Name Then
Sheets(intC2).Move after:=Sheets(intC2 + 1)
End If
Next intC2, intC1
End Sub


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


"Mark" wrote in message
...
I am using Excel 97.

I want to sort worksheets in a workbook so that they are
in alphabetical order.

Can anyone asist me with some code?

Thanks


Mark




All times are GMT +1. The time now is 01:38 AM.

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