Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting date as the name of a new worksheet

Status
Not open for further replies.

protector

Technical User
Mar 16, 2002
18
0
0
NZ
Hi there
I have an Excel Work book that contains various order forms. I have macros that create new work sheets copying the original Order forms depending on which is run. What I want to do, I would like to change the name of a newly created worksheet to the date the work sheet was created. Is this possible? I have got a variable which holds the date but can't figure out how to insert it in the work sheet name
Hope someone can help

Craig
 
Hi people
Have sorted this problem out through trial and error. the code I ended up using is below

Sub Create_New_Orderform()
'
' Create_New_Orderform Macro
' Creates new Order form
'
' Keyboard Shortcut: Ctrl+n
'
'Range("A1:D9").Select
'Selection.Copy
todaysDate = Format(Date, "dd.mm.yy") 'get date

Sheets("Sample order form").Select 'copy order sheet header
Range("A1:D9").Select
Selection.Copy

Set NewSheet = Worksheets.Add 'create new worksheet
NewSheet.Name = todaysDate 'change name of new worksheet
ActiveSheet.Paste 'paste copied header
Columns("A:A").ColumnWidth = 14 'change column widths
Columns("B:B").ColumnWidth = 40
Columns("C:C").ColumnWidth = 10
Columns("D:D").ColumnWidth = 15
End Sub

Thanks
 
Protector,

Congratulations on working out the answer; always satisfying! I want to suggest a way to simplify your code. The following assumes your objective is to create a duplicate of the order form worksheet:

Code:
Sub Create_New_Orderform()
Dim todaysDate As Variant

    Worksheets("Sample Order Form").Copy After:=Sheets(ThisWorkbook.Sheets.Count)
    todaysDate = Format(Date, "dd.mm.yy")
    ActiveSheet.Name = todaysDate
End Sub

Regards,
M. Smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top