LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Worksheets Add & Naming

Hi Patrick,

Thank you very much for taking the time and effort to respond with complete
solution. I like your code and will keep it for future reference.

Again, thank you!

Best regards,
Kevin


Patrick Molloy wrote...
Try the following: run "Main"
The objective
- make sure that all sheets named Sheet1..Sheet65 exist.
If not , add a sheet with the correct name
Once the missing sheets are added, reorder the workbook


Option Explicit
Public Sub Main()
CreateSheets 2, 65
OrderSheets 2, 65
End Sub
Sub CreateSheets(lMin As Long, lMax As Long)
Dim WS As Worksheet
Dim index As Long
For index = lMin To lMax
Set WS = GetSheet("Sheet" & index)
If WS Is Nothing Then
With Worksheets.Add
.Name = "Sheet" & index
End With
End If
Next
End Sub
Public Sub OrderSheets(lMin As Long, lMax As Long)
Dim WS As Worksheet
Dim index As Long
For index = lMin To lMax
Set WS = GetSheet("Sheet" & index)
If Not WS Is Nothing Then
WS.Move after:=Worksheets(index - 1)
End If
Next
End Sub
Private Function GetSheet(SheetName As String) As Worksheet
On Error Resume Next
Set GetSheet = Worksheets(SheetName)
On Error GoTo 0
End Function



Patrick Molloy
Microsoft Excel MVP





 
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
Naming Worksheets LIAMT Excel Worksheet Functions 1 August 21st 05 02:41 PM
Naming worksheets... tojo107 Excel Discussion (Misc queries) 3 April 7th 05 07:29 PM
naming worksheets Shooter Excel Worksheet Functions 1 December 3rd 04 04:09 PM
Naming Worksheets in VBE Don Guillett[_4_] Excel Programming 0 July 18th 03 08:17 PM
Naming Worksheets in VBE Chip Pearson Excel Programming 0 July 18th 03 08:16 PM


All times are GMT +1. The time now is 06:12 AM.

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"