Jmoz092
Board Regular
- Joined
- Sep 8, 2017
- Messages
- 184
- Office Version
- 365
- 2011
- Platform
- Windows
- MacOS
I'm trying to copy a set of sheets that are paired by formulas to each other, a time sheet of sorts, and a corresponding invoice sheet. I can copy them no problem, but I'm having trouble figuring out code to:
1) make a copy of one master and place it after the master sheets then make a copy of the 2nd master and place it after the master sheets AND after the new copy(s) of the first master sheet
2) repeating this as many times as user input requires.
Right Now I'm running each of the code below (thanks Fluff) and then I have to manually drag the Invoice sheet to its matching time sheet.
So we'll wind up with sheets: Data, masterTime, MasterInvoice, copy1MasterTime, copy1MasterInvoice, copy2MasterTime, copy2MasterInvoice, etc,etc
Is there any way to automate this with code?
1) make a copy of one master and place it after the master sheets then make a copy of the 2nd master and place it after the master sheets AND after the new copy(s) of the first master sheet
2) repeating this as many times as user input requires.
Right Now I'm running each of the code below (thanks Fluff) and then I have to manually drag the Invoice sheet to its matching time sheet.
So we'll wind up with sheets: Data, masterTime, MasterInvoice, copy1MasterTime, copy1MasterInvoice, copy2MasterTime, copy2MasterInvoice, etc,etc
Is there any way to automate this with code?
Code:
[COLOR=#454545][FONT='inherit']Sub AddSheetsT()[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim Cnt As Long[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim sTemp As String[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim dSDate As Date[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim Shts As Long[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']
[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] sTemp = InputBox("First Monday for the first worksheet:", "MM-DD-YY")[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] dSDate = CDate(sTemp)[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Shts = (54 - WorksheetFunction.WeekNum(dSDate))[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']
[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']Application.ScreenUpdating = False[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] For Cnt = 1 To Shts[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Sheets("MasterTime”).Copy after:=Sheets(Sheets.Count)[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] ActiveSheet.Name = Format(dSDate, "mm-dd-yy") & " Time"[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] dSDate = dSDate + 7[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Next Cnt[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']End Sub[/FONT][/COLOR]
Code:
[COLOR=#454545][FONT='inherit']Sub AddSheetsI()[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim Cnt As Long[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim sTemp As String[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim dSDate As Date[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Dim Shts As Long[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']
[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] sTemp = InputBox("First Monday for the first worksheet:", "MM-DD-YY")[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] dSDate = CDate(sTemp)[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Shts = (54 - WorksheetFunction.WeekNum(dSDate))[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']
[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']Application.ScreenUpdating = False[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] For Cnt = 1 To Shts[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Sheets("MasterInvoice”).Copy after:=Sheets(Sheets.Count)[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] ActiveSheet.Name = Format(dSDate, "mm-dd-yy") & " Invoice"[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] dSDate = dSDate + 7[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit'] Next Cnt[/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']End Sub[/FONT][/COLOR]
Last edited: