View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JerryG[_5_] JerryG[_5_] is offline
external usenet poster
 
Posts: 1
Default Macro to insert and name a new worksheet


First, make sure you have added a command button where you want it.
Then, here is a macro to be cut and paste into the worksheet with you
command button (and macro assumes it is CommandButton1). Lots of way
err out on a sheet name, so I put in a generic error handler to tel
you if the name could not be updated automatically.


Private Sub CommandButton1_Click()
On Error GoTo NoName
Dim strNewWorksheet As String

strNewWorksheet = Range("A1").Value & " Plan"
Worksheets.Add.Move after:=Worksheets(Worksheets.Count - 3)
ActiveSheet.Name = strNewWorksheet
NoName:
MsgBox "Unable to rename new sheet."
End Sub

Hope this helps and let me know if you have any trouble with this.


JerryG :

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements