Jmoz092
Board Regular
- Joined
- Sep 8, 2017
- Messages
- 184
- Office Version
- 365
- 2011
- Platform
- Windows
- MacOS
If possible, I'd like to alter a code that I've been using so that we can apply it to a macro button in the workbook for the user. I want to change it so that after the user enters the last day of the first week that will create the name of the first worksheet, then the VBA recognizes how many more weeks are remaining in the year and creates the appropriate number of sheets for the rest of the year.
i.e., if we make a new workbook for an existing employee, at the beginning of 2018, we'll enter "1-6-18" into the first input box and then the VBA will recognize that we'll need 26 worksheets (2 weeks per worksheet/pay period) and make them
but, if we hire a new employee in the middle of the year and his/her first week ends 5-19-18 (date entered into first input box when making new workbook), the VBA would recognize that we're in the 20th week of the year and that we'll only need to make 16 worksheets for this new employee.
Here's the code I was using. It was designed to duplicate the master time sheet from 8-25-17 to the end of 2017.
i.e., if we make a new workbook for an existing employee, at the beginning of 2018, we'll enter "1-6-18" into the first input box and then the VBA will recognize that we'll need 26 worksheets (2 weeks per worksheet/pay period) and make them
but, if we hire a new employee in the middle of the year and his/her first week ends 5-19-18 (date entered into first input box when making new workbook), the VBA would recognize that we're in the 20th week of the year and that we'll only need to make 16 worksheets for this new employee.
Here's the code I was using. It was designed to duplicate the master time sheet from 8-25-17 to the end of 2017.
Code:
Sub YearWorkbookStartAtAug25()
Dim sht As Variant
Dim sTemp As String
Dim dSDate As Date
sTemp = InputBox("Date for the first worksheet:", "End of Week?")
dSDate = CDate(sTemp) - 1
Application.ScreenUpdating = False
Worksheets.Add After:=Worksheets(Worksheets.Count), _
Count:=(11 - Worksheets.Count)
For Each sht In Worksheets
sht.Name = Format(dSDate, "mm-dd-yy")
dSDate = dSDate + 14
Next sht
Application.ScreenUpdating = True
End Sub