Create sheet for every day of month using Master template, name each sheet as per day of month. VBA

MeaclH

New Member
Joined
Apr 2, 2014
Messages
43
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Gday everyone,

I have found a few VBA codes that do the trick but I have a slightly different need.
I would like to have a workbook for every month that we have operations. Each workbook needs to contain a sheet for each day of the month. Some of the codes that I have found prompt an input box for month and year etc which would be nice.
I would like to run a VBA code that creates a sheet for each day of the month using the Master sheet as a template, and have each sheet named as per the day of month. Like I say I have found some codes to do the above but what I also need is to figure out how to put the corresponding date on each sheet a certain cell (H1). So it's easily identifiable to our team what date they are working on, rather than the sheet tabs at the bottom.

Any ideas how to tie it all together, when creating all the sheets from the master? Also, we are down under, so any date format would be appreciated in DD MM YYYY :)

Thanks for your help

Cheers,
Hayden
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this:

VBA Code:
Public Sub Create_Daily_Sheets()

    Dim inputMonthYear As String, inputDate As Date
    Dim d As Date
    
    inputMonthYear = InputBox("Enter month and year (MM YYYY)", "Create sheet for every day of month", Format(Date, "MM YYYY"))
    If inputMonthYear = "" Then Exit Sub
        
    inputDate = CDate("01 " & inputMonthYear)
    Application.ScreenUpdating = False
    With ActiveWorkbook.Worksheets("Master")
        For d = DateSerial(Year(inputDate), Month(inputDate), Day(inputDate)) To DateSerial(Year(inputDate), Month(inputDate) + 1, 0)
            .Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
            ActiveSheet.Name = Format(d, "dd mm")
            ActiveSheet.Range("H1").Value = d
            ActiveSheet.Range("H1").NumberFormat = "dd mm yyyy"
        Next
        .Activate
    End With
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 1
Solution
Try this:

VBA Code:
Public Sub Create_Daily_Sheets()

    Dim inputMonthYear As String, inputDate As Date
    Dim d As Date
   
    inputMonthYear = InputBox("Enter month and year (MM YYYY)", "Create sheet for every day of month", Format(Date, "MM YYYY"))
    If inputMonthYear = "" Then Exit Sub
       
    inputDate = CDate("01 " & inputMonthYear)
    Application.ScreenUpdating = False
    With ActiveWorkbook.Worksheets("Master")
        For d = DateSerial(Year(inputDate), Month(inputDate), Day(inputDate)) To DateSerial(Year(inputDate), Month(inputDate) + 1, 0)
            .Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
            ActiveSheet.Name = Format(d, "dd mm")
            ActiveSheet.Range("H1").Value = d
            ActiveSheet.Range("H1").NumberFormat = "dd mm yyyy"
        Next
        .Activate
    End With
    Application.ScreenUpdating = True
   
End Sub
John, a big hearty thank you from me. This code works unbelievably well!
Cheers
 
Upvote 0
John, a big hearty thank you from me. This code works unbelievably well!
Cheers
Hi John,

Following this thread, I am looking to create a daily worksheet for the month copying from a template. How do I expand this code to do that? When I use the code, it just created 1 day for me but not all 30 days for September.
 
Upvote 0
The code works for the OP's specific case, so if you can't determine why it isn't working for you I suggest you start a new thread, detailing your precise requirements.
 
Upvote 0

Forum statistics

Threads
1,220,928
Messages
6,156,876
Members
451,386
Latest member
Jeaux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top