Ryan has an Excel worksheet that he needs to use for each of 3 shifts every day. He makes a copy of this worksheet for each shift, each day, over and over. It seems to Ryan that it would be helpful if he had a macro that could copy the master worksheet 3 times for each day in a month, naming the worksheets "February 1 Shift 1," "February 1 Shift 2," etc. He can't find a macro to do something like this and was wondering if anyone could help.
This actually doesn't take that long to put together as a macro. The trick is to remember that the macro needs to copy your master worksheet 3 times for each day in the desired month. This also implies that the macro needs to determine how many days there are in the month. Once this is known, you can set up two nested For...Next loops to handle the actual creation process.
Sub CopyShiftSheets()
Dim iDay As Integer
Dim iShift As Integer
Dim iNumDays As Integer
Dim wMaster As Worksheet
Dim sTemp As String
iMonth = 9 ' Set to month desired, 1-12
iCurYear = Year(Now())
iNumDays = Day(DateSerial(iCurYear, iMonth + 1, 0))
Set wMaster = Worksheets("Master") 'change to name of master
For iDay = 1 To iNumDays
For iShift = 1 To 3
sTemp = MonthName(iMonth) & " " & iDay & " Shift " & iShift
wMaster.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = sTemp
Next iShift
Next iDay
End Sub
Note that the number of the desired month (in this case September) is assigned to the iMonth variable and that iCurYear is set to the current year. The number of days in that month and year is then calculated and stored in iNumDays.
The two For...Next loops go through each day and each shift, copying the Master worksheet and renaming it. When you are done, your workbook will have all the desired worksheets, named correctly. You'll want to be careful, however, that you don't run the macro twice for the same month. If you do, an error is generated because you will have duplicate-named worksheets in the workbook.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13730) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
Sometimes it may be helpful for a macro to know exactly where it is being executed. This tip provides a way that you can ...
Discover MoreMacros can be used to change the formatting of your worksheet, if desired. One change you might want to make is to the ...
Discover MoreMacros are very powerful, but you may not want them to always be available to a user. Here are some ways you can limit ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments