mylinenum = Range("linenum")
If Range("linenum").Value < 1000 Then
mylinenum = Format(mylinenum, "000")
ElseIf Range("linenum").Value > 999 Then
mylinenum = Format(mylinenum, "0000")
End If
this works fine to name the worksheets 005, 010, 015 etc. But it will not
sort the worksheets. Can this be done using numbers only for the worksheet
names after I have formatted the worksheet names this way? The following is
the sort code...
Sub SortTheSheets()
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 CInt(Mid(Worksheets(N).Name, 6)) > _
CInt(Mid(Worksheets(M).Name, 6)) Then
Worksheets(N).Move Before:=Worksheets(M)
End If
Else
If CInt(Mid(Worksheets(N).Name, 6)) < _
CInt(Mid(Worksheets(M).Name, 6)) Then
Worksheets(N).Move Before:=Worksheets(M)
End If
End If
Next N
Next M
End Sub
Sub AlphaSortWorksheets()
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
SortDescending = False
FirstWSToSort = 1
LastWSToSort = Worksheets.Count
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
--
Gary
"jnf40" <jn...@discussions.microsoft.com> wrote in message
news:A7FC0724-1228-41A9...@microsoft.com...
.
"jnf40" <jn...@discussions.microsoft.com> wrote in message news:A7FC0724-1228-41A9...@microsoft.com...
"Jim Cone" wrote:
> You can try the free Excel add-in "Excel Extras".
> By default It sorts sheets in true numerical order.
> (It can also use the standard MS sort order where 10 comes before 2.)
> It does other nice stuff like creating a linked Table of Contents sheet.
> Download from ... http://www.realezsites.com/bus/primitivesoftware
> No registration required.
> --
> Jim Cone
> San Francisco, USA
>
> ..
"jnf40" <jn...@discussions.microsoft.com>
wrote in message
"Gary Keramidas" wrote:
> in your example, 005, 010, 015, what order are they supposed to be in after
> they're sorted?
>
> --
>
>
> Gary
>
>
> "jnf40" <jn...@discussions.microsoft.com> wrote in message
> news:A7FC0724-1228-41A9...@microsoft.com...
when i ran the code i posted, the sheets were in this order:
005,007,010,015
so, i guess i don't see what you do or i am missing something
--
Gary
"jnf40" <jn...@discussions.microsoft.com> wrote in message
news:3BAD2D04-6278-4073...@microsoft.com...
--
Gary
"jnf40" <jn...@discussions.microsoft.com> wrote in message
news:A7FC0724-1228-41A9...@microsoft.com...