Thread
:
Order worksheets by cell nunber
View Single Post
#
2
Posted to microsoft.public.excel.programming
Chip Pearson
external usenet poster
Posts: 7,247
Order worksheets by cell nunber
Put the code in a standard code module, not the code module of a
worksheet.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"SpeeD" wrote in message
...
Hi chip.
First of all, thank you for ansewring me post!! :-)
Iīve tried your code (copied it to the DECLARATIONS in
the wanted Sheet, but, it didnīt do nothing.... Iīve
inserted several nunbers in A! but hte sheet didnīt
switch itīs order.
What am i doind wrong???
Thanks a lot..
SpeeD
-----Original Message-----
Try something like the following:
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 Worksheets(N).Range("A1")
Worksheets(M).Range("A1") Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If Worksheets(N).Range("A1") <
Worksheets(M).Range("A1") Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Sub
To sort sheets alphabetically, see
http://www.cpearson.com/excel/sortws.htm
. The code
above is just
modification of the code on my web site.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"SpeeD" wrote in message
...
Hi.
I need to (automaticly) order the worksheets in the a
order given by a cell (a1) inside themselfs...
Can i do this???
If not possible, can order them in alfebetical order???
how??
thanks a lot!
SpeeD
.
Reply With Quote
Chip Pearson
View Public Profile
Find all posts by Chip Pearson