excelguy23
New Member
- Joined
- Aug 1, 2008
- Messages
- 4
Hi all. Need some help with a macro I'm currently using. Before I get into that this is what it already does:
Here is the Macro code I'm working with. Thank you in advance!!!
- Inserts an existing worksheet template and places it at the end (or after all) the existing worksheets.
- Automatically rename the inserted worksheet (via my worksheet template) in sequence to the existing worksheets
Example: So let's say I have 3 existing worksheets titled Sheet1, Sheet2, Sheet3 (that's basically the default naming Excel uses). But would when I insert a new worksheet (via my worksheet template) it is shown as Sheet. And if I insert another one, it would be Sheet (2).
So basically it is showing as such:
Sheet1, Sheet2, Sheet3, Sheet, Sheet (2)
What I would like the macro to do is automatically rename those last 2 worksheets (and any subsequent worksheets thereafter) in sequential order. Basically displaying it as such:
Sheet1, Sheet2, Sheet3, Sheet4, Sheet5...(and so on and so forth)
Here is the Macro code I'm working with. Thank you in advance!!!
Sub Macro1()
Dim sh As Worksheet
Dim shName As String
Dim n As Integer
'Name of the sheet template
shName = "Sheet.xlt"
'Insert sheet template
With ThisWorkbook
Set sh = Sheets.Add(Type:=Application.TemplatesPath & shName, _ After:=.Sheets(.Sheets.Count))
End With
End Sub
Dim sh As Worksheet
Dim shName As String
Dim n As Integer
'Name of the sheet template
shName = "Sheet.xlt"
'Insert sheet template
With ThisWorkbook
Set sh = Sheets.Add(Type:=Application.TemplatesPath & shName, _ After:=.Sheets(.Sheets.Count))
End With
End Sub