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 . |
All times are GMT +1. The time now is 03:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com