HI guys I have a pretty heafty workbook wich is nearly done bar optimising and sorting options..
Many sheets many different names ! but the ones I want to select as a range to be sorted by another sub that is called all start with PP as the tab name!
*
I thought the below code would help. I've attempted to modify to no avail :-? any advice guys ??
*
Thanks
*
Sub WorksheetsSortAscending()
*
*** Dim sCount As Integer, i As Integer, j As Integer
*** sCount = Worksheets.Count
*** If sCount = 1 Then Exit Sub
** For i = Worksheet.Name Like "PP*" To sCount - 1*** For j = i + 1 To sCount
*** If Worksheets(j).Name < Worksheets(i).Name Then
*** Worksheets(j).Move before:=Worksheets(i)
***
End If
Next j
Next i
End Sub
*
Code to be called to sort selected range of sheets this works well when manually selecting a range of sheets !!!
*
Sub SortWorksheets()
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
Dim AscDesc
*
AscDesc = MsgBox(prompt:="Sort worksheets in ascending order?", _
Title:="Sort Order", _
Buttons:=vbYesNoCancel)
If AscDesc = vbYes Then
SortDescending = False
ElseIf AscDesc = vbNo Then
SortDescending = True
Else
Exit Sub
End If
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 UCase(Worksheets(N).Name) > UCase(Worksheets(M).Name) Then
Worksheets(N).Move before:=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name) Then
Worksheets(N).Move before:=Worksheets(M)
End If
End If
Next N
Next M
End Sub
*
Thanks again guys
Bookmarks