close

I would like to be able to insert a new worksheet(s) into a notebook with a
macro. The new spreadsheet must appear at the end and if possible the tab be
named in numerical order (i.e. 1, 2, 3, 4,...etc.). Is this possible and if
so how do you write it?
Thank you for the help and suggestions.
kristin from nys

Here's a little modification on Chip Pearson's quot;SortWorksheetsquot;
macro..........it seems to do the job you ask.........

Sub InsertWorksheetAndSortTabs()
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
Sheets.Add
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 lt;gt; .Item(N).Index - 1 Then
MsgBox quot;You cannot sort non-adjacent sheetsquot;
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) gt; UCase(Worksheets(M).Name) Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) lt; UCase(Worksheets(M).Name) Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Subhth
Vaya con Dios,
Chuck, CABGx3quot;Kristin from NYSquot; wrote:

gt; I would like to be able to insert a new worksheet(s) into a notebook with a
gt; macro. The new spreadsheet must appear at the end and if possible the tab be
gt; named in numerical order (i.e. 1, 2, 3, 4,...etc.). Is this possible and if
gt; so how do you write it?
gt; Thank you for the help and suggestions.
gt; kristin from nys

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()