How can I get excel to label sheets automatically? eg: dates.
Start a new workbook
Add this code to a general module in that workbook's project
Option Explicit
Sub testme()
Dim iCtr As Long
Dim NewWkbk As Workbook
Dim HowMany As Long
Dim StartDate As Date
StartDate = DateSerial(Year(Date), Month(Date) + 1, 1)
StartDate = Application.InputBox(prompt:="Enter a date in the month you
want", _
Type:=1, Default:=Format(StartDate, "mmmm dd, yyyy"))
If Year(StartDate) < 2005 _
Or Year(StartDate) 2010 Then
Exit Sub
End If
StartDate = DateSerial(Year(StartDate), Month(StartDate), 1) 'First of the
month!
HowMany = Day(DateSerial(Year(StartDate), Month(StartDate) + 1, 0))
Set NewWkbk = Workbooks.Add(1) 'single sheet
NewWkbk.Sheets.Add Count:=HowMany - 1
For iCtr = 1 To HowMany
NewWkbk.Worksheets(iCtr).Name _
= Format(StartDate - 1 + iCtr, "yyyy_mm_dd")
Next iCtr
End Sub
Back to excel
put a giant button from the Forms toolbar on the first worksheet in that new
workbook. Assign this macro to the button.
Save this workbook.
Open the workbook when you want to create a new workbook for the month and click
the giant button.
Adrian wrote:
I want Excel to label my sheets automatically, because I make a workbook
every month and I don't feel like entering every date on every tab. Is this
possible?
--
Dave Peterson
|