|
|
|
|
|
|
Excel
|
Add a sheet with today's date
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2002
|
Submitted by:
|
Justinlabenne
|
Description:
|
Whenever this code is run a sheet named with the current date is selected, or if the sheet does not exist, the sheet is created.
|
Discussion:
|
I have worked with a lot of users who were adding a new sheet to their workbook every week with the current date. This code automated an already simple but tedious process by adding a new sheet with the current date. The code checks to ensure that another sheet of the same name is not added by attempting to activate the sheet, and based on whether it exists or not, the sheet is added.
|
Code:
|
instructions for use
|
Option Explicit
Sub AddSheets_Today()
Dim szToday As String
szToday = Format(Date, "mmm-dd-yy")
On Error GoTo MakeSheet
Sheets(szToday).Activate
Exit Sub
MakeSheet:
Sheets.Add , Worksheets(Worksheets.Count)
ActiveSheet.Name = szToday
End Sub
|
How to use:
|
- Open an Excel Workbook
- Copy the code
- Press Alt + F11 to open the Visual Basic Editor (VBE)
- Select INSERT > MODULE from the menubar
- Paste code into the right pane
- Press Alt+Q to return to Excel
- Save workbook before any other changes
|
Test the code:
|
- Go to TOOLS > MACRO > MACROS
- When the dialog appears, select {AddSheets_Today}
- Press Run
|
Sample File:
|
AddTodaySheet2.zip 7.06KB
|
Approved by mdmackillop
|
This entry has been viewed 209 times.
|
|