#1   Report Post  
Posted to microsoft.public.excel.misc
Kristin from NYS
 
Posts: n/a
Default Spreadsheet Macro

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
CLR
 
Posts: n/a
Default Spreadsheet Macro

Here's a little modification on Chip Pearson's "SortWorksheets"
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 < .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 Befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name) Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Sub


hth
Vaya con Dios,
Chuck, CABGx3


"Kristin from NYS" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a macro that will exit a spreadsheet Dave Doc New Users to Excel 2 January 26th 06 01:41 PM
format macro Jonathan Cooper Excel Discussion (Misc queries) 5 January 9th 06 08:49 PM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
How do I set up a macro to forward an Excel Spreadsheet via email John Excel Discussion (Misc queries) 0 August 17th 05 08:41 PM
Sample spreadsheet of using macro Isaac Excel Worksheet Functions 2 November 19th 04 02:22 AM


All times are GMT +1. The time now is 03:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"