|
Home > Structure > Workbook > Add Worksheets Create Excel Workbooks Worksheets AutomaticallyCreate worksheets automatically when file opens at start of month - watch the video below, to see the steps. In another example, click a worksheet button to create monthly workbooks and worksheets for entire year. |

To make the most of Excel data analysis features, like pivot table and filters, it's best to have your data in one main table. However, sometimes you need to work with your data in a less than ideal setup, such as separate worksheets for each month, or in a different file for each month, with daily worksheet.
The macros on this page will help you set those up quickly, instead of manually creating the worksheets and workbooks.
At the end of the page, you can download the sample Excel files with the macro VBA code that you need for these repetitive tasks.

In this video, see how to auto insert a new worksheet with the month name, when an Excel workbook opens at the start of the month.
There are written steps below the video, and you can download the sample file at the end of the page.
Someone asked me how to automatically insert a new month sheet, when they opened their Excel file at the betinning of the month. So, I created this macro and sample file, and the video that shows how the macro works automatically.
Before writing an Excel macro, make a plan for what the macro needs to do.
-- 1) Overall Goal
-- 2) Required Steps
The plans for the worksheet macro are shown below
For this macro, the goal is to add a new, blank worksheet with the month name, when the Excel file opens. This should only happen at the start of the month, if the current month's sheet doesn’t exist already.
Here are the basic steps that this macro needs to do:
In the next section, you'll see how to do those steps with Excel VBA code in a macro.
First, to get the month name in Excel VBA code, you can combine two VBA functions:
In this example, the worksheet names will have this format: yyyy_mm
Here is the VBA code to return the current date, as a text string, in yyyy_mm format:
Format(Date, "yyyy_mm")
Instead of using the yyyy_mm date format, you could use one of the following formats in the VBA code, if you prefer.
NOTE: If there are multiple years of data in the workbook, be sure to include the year number in the date string, e.g. yyyy_mmm
Format(Date, "mm_mmm")
In the macro, there is a variable named strName. It stores the results from the Format and Date formula, as a text string.
strName = Format(Date, "yyyy_mm")
Next, the Excel VBA code will check for an existing sheet with the current month name, in the format that your macro uses. For this step, the code uses the strName variable that stores the date text string.
First, the code tries to get the name of the sheet named with the date text string (strName)
Sheets(strName).Name
Next, the code uses the VBA Len function to check the length of that sheet name, and see if it is greater than zero characters - True or False
Len(Sheets(strName).Name) > 0
In the macro, there is a variable named bCheck. It stores the results from the length test formula, as a Boolean value (true or false)
bCheck = Len(Sheets(strName).Name) > 0
If the workbook already has a sheet with the current month's name:
If the workbook does NOT a sheet with the current month's name:
The final step in the macro is to add a new worksheet, if needed, using the date text string
If bCheck = False Then
Set ws = Worksheets.Add(Before:=Sheets(1))
ws.Name = strName
End If
Here is the completed macro code to add a new worksheet, if needed, using a formatted date string as its name. This macro is stored on a regular code module in the workbook
Sub AddMonthWkst()
Dim ws As Worksheet
Dim strName As String
Dim bCheck As Boolean
On Error Resume Next
strName = Format(Date, "yyyy_mm")
bCheck = Len(Sheets(strName).Name) > 0
If bCheck = False Then
Set ws = Worksheets.Add(Before:=Sheets(1))
ws.Name = strName
End If
End Sub
To make the AddMonthWkst macro run automatically, when the workbook opens, you’ll create a Workbook_Open event. Instead of storing this event code in a regular code module, you'll store it in the Workbook module.
To add this code to your own workbook:

Here is the event code to copy and paste:
Private Sub Workbook_Open()
'add new sheet each month
AddMonthWkst
End Sub
Set up a momthly template sheet in your workbook, and automatically create a copy of that master sheet each month, named for the month and year, in yyyy_mm format.
Note: To add multiple month sheets, go to the next section: Add Multiple Month Sheets
This macro runs automatically when the workbook opens, and macros are enabled. There are two bits of code in the sample workbook. There is a sample file with these macros in the Download section below.
Watch this video to see the steps, and the code and instructions are below the video.
This is the monthly template master sheet, from the sample file, and it will be copied to create a new sheet each month

In the ThisWorkbook code module, there is a Workbook_Open event, and it runs the AddMonthWkst macro.
Private Sub Workbook_Open() AddMonthWkst End Sub
In the modSheets code module, there is macro named AddMonthWkst. This macro:
NOTE: You can change the master sheet name, and the date formatting, to match what you need in your workbook
Sub AddMonthWkst()
Dim ws As Worksheet
Dim wsM As Worksheet
Dim strName As String
Dim bCheck As Boolean
On Error Resume Next
Set wsM = Sheets("Wkst_Master")
strName = Format(Date, "yyyy_mm")
bCheck = Len(Sheets(strName).Name) > 0
If bCheck = False Then
'add new sheet after Instructions
wsM.Copy After:=Sheets(1)
ActiveSheet.Name = strName
End If
Set wsM = Nothing
End Sub
Set up a Master sheet, named Wkst_Master, in your workbook, and use this macro to automatically create copies of that sheet, for multiple months. Get the sample file in the Download section below.
To customize the sheets, go to the sheet named Wkst_Admin, and enter the year, month, sheet name and sheet title information. For the sheet names and sheet titles:
The macro will replace those characters when creating the sheets.

In the modSheets code module, there is macro named AddMultiMonthWksts. This macro:
NOTE: If you change the Admin sheet or Master sheet names, also change those names in the code.
Sub AddMultiMonthWksts()
Dim wsA As Worksheet
Dim wsM As Worksheet
Dim wsMth As Worksheet
Dim bCheck As Boolean
Dim wsYr As Long
Dim strCell As String
Dim strTitle As String
Dim strTabs As String
Dim wsTitle As String
Dim wsTab As String
Dim wsStart As Long
Dim wsEnd As Long
Dim wsSht As Long
Dim shDate As Date
Dim strMthT As String
Dim strMthTb As String
Dim strYtT As String
Dim strYrTb As String
Dim strMsg As String
On Error Resume Next
Set wsA = Sheets("Wkst_Admin")
Set wsM = Sheets("Wkst_Master")
strMsg = "Could not add all sheets"
On Error Resume Next
With wsA
wsYr = .Range("wsYr").Value
If wsYr = 0 Then
strMsg = "Please enter year number" _
& vbCrLf _
& "and try again."
GoTo errHandler
End If
strCell = .Range("wsCell").Value
strTitle = .Range("wsTitle").Value
strTabs = .Range("wsTabs").Value
wsStart = .Range("wsStart").Value
wsEnd = .Range("wsEnd").Value
If wsStart = 0 Or wsEnd = 0 Then
strMsg = "Please enter month start " _
& "and end numbers" _
& vbCrLf _
& "and try again."
GoTo errHandler
End If
End With
On Error GoTo errHandler
'add sheets before master sheet
For wsSht = wsStart To wsEnd
strMsg = "Could not get date for" _
& vbCrLf _
& "Year " & wsYr _
& " and Month " & wsSht
shDate = DateSerial(wsYr, wsSht, 1)
strMsg = "Could not get sheet name for" _
& vbCrLf _
& "Year " & wsYr _
& " and Month " & wsSht
wsTab = Range("wsTabs").Value
wsTab = Replace(wsTab, "xxxx", _
Format(shDate, "mmmm"))
wsTab = Replace(wsTab, "xxx", _
Format(shDate, "mmm"))
wsTab = Replace(wsTab, "xx", _
Format(shDate, "mmm"))
wsTab = Replace(wsTab, "yyyy", _
Format(shDate, "yyyy"))
wsTab = Replace(wsTab, "yy", _
Format(shDate, "yy"))
On Error Resume Next
bCheck = Len(Sheets(wsTab).Name) > 0
On Error GoTo errHandler
If bCheck = False Then
'add new sheet after Instructions
strMsg = "Could not get add sheet " & wsTab
wsM.Copy Before:=wsM
With ActiveSheet
.Name = wsTab
If strCell <> "" Then
wsTitle = strTitle
wsTitle = Replace(wsTitle, "xxxx", _
Format(shDate, "mmmm"))
wsTitle = Replace(wsTitle, "xxx", _
Format(shDate, "mmm"))
wsTitle = Replace(wsTitle, "xx", _
Format(shDate, "mm"))
wsTitle = Replace(wsTitle, "yyyy", _
Format(shDate, "yyyy"))
wsTitle = Replace(wsTitle, "yy", _
Format(shDate, "yy"))
.Range(strCell).Value = wsTitle
End If
End With
End If
Next wsSht
exitHandler:
Set wsA = Nothing
Set wsM = Nothing
Set wsMth = Nothing
Exit Sub
errHandler:
MsgBox strMsg
Resume exitHandler
End Sub
In the download section below, there is another sample Excel file that automatically creates worksheets, and it creates workbooks too, created by Roger Govier.
You can use this macro at the end of the year, when you want to set up your files for the upcoming year.


After you download the Create Workbook macro file, go to Windows Explorer, find the downloaded file, and follow these steps to unblock it:
Next, open the sample file, and go to the Information worksheet. There's a notes section there, so start by reading that.
Remember -- the monthly workbooks will all be created in the same folder where the Create Workbooks macro file is stores.

Within each workbook, the macro will create a worksheet for each day of the month.

There are two versions of the Create Workbooks Macro workbook:
Both versions are in the Download section below.
Don't miss my monthly Excel newsletter! You'll get quick tips, article links, and a bit of fun. Add your email, and click Sign Up.
Next, when you get my reply, click the Confirm button. I add this step to protect you from spam!
Last updated: July 10, 2025 3:24 PM