Try this:
Sub SortWorksheets()
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
Dim ValN, ValM
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
ValM = ActiveWorkbook.Worksheets(M).Cells(1, "J").Value 'Change 1,"J"
to the row and column # you need
For N = M To LastWSToSort
ValN = ActiveWorkbook.Worksheets(N).Cells(1, "J").Value 'Change
1,"J" to the row and column # you need
Debug.Print ValM, ValN
If SortDescending = True Then
If ValN > ValM Then
Worksheets(N).Move Before:=Worksheets(M)
End If
Else
If ValN < ValM Then
Worksheets(N).Move Before:=Worksheets(M)
End If
End If
Next N
Next M
End Sub
Patrick said:
Hey!
I have tried, and failed. :-( Miserably. :-( Many times. :-(
Any advice?
Patrick
Barb Reinhardt said:
Take a look at this macro. I suspect you should be able to modify it to get
what you want.
http://www.cpearson.com/excel/sortws.htm
Patrick said:
Hi!
I have about 850 worksheets that I need to sort in the workbook based on the
value of a cell in each worksheet. [The worksheets correspond to one of six
regional areas - and I need to group them] I can't find this functionality
anywhere, and I can't find where to start in trying to program it.
Thank you!