I have a weekly schedule which I duplicate often. I have Frankensteined a vba (from too many sources to list) that duplicates the first worksheet, names the sheet, and inserts the date. I get information for the variables from 3 InputBoxs. To simplify this I wanted to create a UserForm that has all the input fields for the variables (already created). However I do not know how to have these textboxes transfer the content to the variables and run the script.
I have googled this and searched here, however the only guides I can find shows how to link the UserForm to cells in the table. Can someone help me with how to do this?
Thank you for any help anyone can offer
This is the code I have managed to put together
I have googled this and searched here, however the only guides I can find shows how to link the UserForm to cells in the table. Can someone help me with how to do this?
Thank you for any help anyone can offer
This is the code I have managed to put together
VBA Code:
Sub Create6()
'Updateby Extendoffice
Dim I As Long
Dim xNumber As Integer
Dim xCurrent As Integer
Dim xName As String
Dim xActiveSheet As Worksheet
Dim StartDate As Date
Dim nSheets As Integer
On Error Resume Next
Application.ScreenUpdating = False
' Number of start worksheet
nSheets = ThisWorkbook.Sheets.Count
Set xActiveSheet = ActiveSheet
StartDate = InputBox("Start date")
xCurrent = InputBox("Start Week")
xNumber = InputBox("End Week")
For I = xCurrent To xNumber
xName = ActiveSheet.Name
ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
ActiveSheet.Name = "W-" & I
Range("A2").Value = ActiveSheet.Name
Range("A3").Value = ThisWorkbook.Sheets.Count
Range("A4").Value = nSheets
If ThisWorkbook.Sheets.Count = nSheets + 1 Then
Range("D4").Value = StartDate
Range("D5").Value = Range("D4").Value + 1
Range("D6").Value = Range("D5").Value + 1
Range("D7").Value = Range("D6").Value + 1
Range("D8").Value = Range("D7").Value + 1
Range("D9").Value = Range("D8").Value + 1
Else
Range("D4").Value = Worksheets(xIndex - 1).Range(D4) + 7
Range("D5").Value = ActiveSheet.Previous.Range(D5) + 7
Range("D6").Value = 3
Range("D7").Value = 4
Range("D8").Value = 5
Range("D9").Value = DateAdd("d", 7, "ActiveSheet.Previous.Range(D5)")
Range("B14").Value = ActiveSheet.Index
Range("B15").Value = ActiveSheet.Index - 1
End If
Next
xActiveSheet.Activate
Application.ScreenUpdating = True
End Sub