Add and Name a New Worksheet

Add and Name a New Worksheet

[vb autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true” 1=”and” 2=”Name” 3=”1″ language=”title="Add”]
Private Sub AddNameNewSheet1()
‘Doesn’t check for errors
Dim Newname As String
Newname = inputBox("Name for new worksheet?")
If Newname <> "" Then
Sheets.Add Type:=xlWorksheet
ActiveSheet.Name = Newname
End If
End Sub
[/vb]
Additional options for adding a sheet
[vb autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true” title=”Add and Name 2″]
Private Sub AddNameNewSheet2()
Dim CurrentSheetName As String

‘Remember where we started
‘Not needed if you don’t want to return
‘to where you started but want to stay
‘on the New Sheet

CurrentSheetName = ActiveSheet.Name

‘Add New Sheet
Sheets.Add

‘Make sure the name is valid
On Error Resume Next

‘Get the new name
ActiveSheet.Name = inputBox("Name for new worksheet?")

‘Keep asking for name if name is invalid
Do Until Err.number = 0
Err.Clear
ActiveSheet.Name = inputBox("Try Again!" _
& vbCrLf & "Invalid Name or Name Already Exists" _
& vbCrLf & "Please name the New Sheet")
Loop
On Error GoTo 0

‘Go back to where you started
‘Not needed if you don’t want to return to where you
‘started but want to stay on the New Sheet
Sheets(CurrentSheetName).Select

End Sub[/vb]