Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Order worksheets by cell nunber

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



.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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
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
Does the order of worksheets matter ? kittronald Excel Worksheet Functions 1 August 20th 11 06:56 PM
printing order of worksheets pkeegs Excel Discussion (Misc queries) 0 November 29th 06 08:42 PM
Print order of worksheets Stray Doug Excel Discussion (Misc queries) 3 September 21st 05 12:37 AM
How do I put worksheets in alphabetical order DLee Excel Worksheet Functions 1 July 27th 05 08:41 PM
nunber format in Excel 2000 Erle Excel Discussion (Misc queries) 3 November 30th 04 07:27 PM


All times are GMT +1. The time now is 07:46 PM.

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"