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 cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using TODAY() function to title a worksheet 2

Status
Not open for further replies.

sdfreed

Materials
Joined
Oct 26, 2003
Messages
6
Location
US
I am writing a program in VBA where I want the macro to run a daily result to create a new worksheet titled: "today's date" Orders

I know how to use the functions today() and now() within Excel, but I can't figure out the code to make it title the worksheet with the current date.

Can anyone can help?

Thanks

SDFreed
 
Try the following code, Excel doesnt like / in the worksheet name so the code replaces all the "/" with a "." eg the date 27/10/03 becomes 27.10.03

Sub Macro1()

sheetname = Date
namelength = Len(sheetname)
For t = 1 To namelength
If Mid$(sheetname, t, 1) = "/" Then
sheetname = Left$(sheetname, t - 1) & "." & Right$(sheetname, namelength - t)
End If
Next
Sheets.Add
ActiveSheet.Name = sheetname

End Sub
 
Try this:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/19/2003 by DBP
'

'
Range("a1").Value = "= TEXT(TODAY(), ""mmm dd yyy"") & "" REPORT"""

Range("A1:J1").Select
With Selection
.HorizontalAlignment = xlCenterAcrossSelection
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

Cheers,
KE4GFM
 
I am using this piece of a code:

Sub report()
sheetname = "Report " & Left((Now), 2) & "-" & Mid((Now), 4, 2) & "-" & Mid((Now), 9, 2)
Sheets.Add
ActiveSheet.Name = sheetname
End Sub
m777182
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top