Need help to solve a tricky situation:
I have an workbook with two sheets: "sheet1" containing on column A the working days of a year and on column B the months of a year and sheet "Template", which contains a template (with formulas in it).
(1)By clicking a button I want to (2) create 12 workbooks (1 for each month of the year), each workbook (3) having between 19 and 23 worksheets (depends how many working days are in a month). Also the workbook has to (4) have the name of the month and the (5) name of the worksheets has to be copied from the values contained in the column A. (for example, the first workbook has to have the name "January" and has to have 22 worksheets, with the name "03.01.2019", "04.01.2019" ..."31.01.2019"). Also, (6) in each worksheet I need the template from the "Template" sheet in the "master" workbook.
I'm new to VBA, tried different approaches (found here, on this forum) of this problem, but haven't been able to solve it yet. So far I managed to create a workbook with multiple sheets, each having the name of the day.
Any help is much appreciated. Thank you in advance.
Here is what I managed so far:
Sub AddMultiSheetswithNames()
Worksheets.Add after:=Sheet1, Count:=20
Dim p, q As Integer
Dim sheetname
sheetname = Array("03.01.2019", "04.01.2019", "07.01.2019", "08.01.2019", "09.01.2019", "10.01.2019", "11.01.2019", "14.01.2019", "15.01.2019", "16.01.2019", "17.01.2019", "18.01.2019", "21.01.2019", "22.01.2019", "23.01.2019", "25.01.2019", "28.01.2019", "29.01.2019", "30.01.2019", "31.01.2019")
p = Worksheets.Count
For q = 1 To p
With Worksheets(q)
'sheetname = InputBox("Enter name for worksheet")
.Name = sheetname(q)
End With
Next q
End Sub
I also found a code for copying data from a worksheet to another, but haven't figure it out how to integrate it in the code above
Sub CopySeriesToNewSheet(src As Worksheet, Start As Long, Last As Long, _
name As String)
Dim wb As Workbook : Set wb = Workbooks.Add
Dim tgt As Worksheet
Set tgt = wb.Sheets(1)
tgt.name = name
src.Range("A" & Start & ":N" & Last).Copy
tgt.Range("A1:N" & Last).PasteSpecial xlPasteAll
wb.SaveAs name
wb.Close
End Sub
I have an workbook with two sheets: "sheet1" containing on column A the working days of a year and on column B the months of a year and sheet "Template", which contains a template (with formulas in it).
(1)By clicking a button I want to (2) create 12 workbooks (1 for each month of the year), each workbook (3) having between 19 and 23 worksheets (depends how many working days are in a month). Also the workbook has to (4) have the name of the month and the (5) name of the worksheets has to be copied from the values contained in the column A. (for example, the first workbook has to have the name "January" and has to have 22 worksheets, with the name "03.01.2019", "04.01.2019" ..."31.01.2019"). Also, (6) in each worksheet I need the template from the "Template" sheet in the "master" workbook.
I'm new to VBA, tried different approaches (found here, on this forum) of this problem, but haven't been able to solve it yet. So far I managed to create a workbook with multiple sheets, each having the name of the day.
Any help is much appreciated. Thank you in advance.
Here is what I managed so far:
Sub AddMultiSheetswithNames()
Worksheets.Add after:=Sheet1, Count:=20
Dim p, q As Integer
Dim sheetname
sheetname = Array("03.01.2019", "04.01.2019", "07.01.2019", "08.01.2019", "09.01.2019", "10.01.2019", "11.01.2019", "14.01.2019", "15.01.2019", "16.01.2019", "17.01.2019", "18.01.2019", "21.01.2019", "22.01.2019", "23.01.2019", "25.01.2019", "28.01.2019", "29.01.2019", "30.01.2019", "31.01.2019")
p = Worksheets.Count
For q = 1 To p
With Worksheets(q)
'sheetname = InputBox("Enter name for worksheet")
.Name = sheetname(q)
End With
Next q
End Sub
I also found a code for copying data from a worksheet to another, but haven't figure it out how to integrate it in the code above
Sub CopySeriesToNewSheet(src As Worksheet, Start As Long, Last As Long, _
name As String)
Dim wb As Workbook : Set wb = Workbooks.Add
Dim tgt As Worksheet
Set tgt = wb.Sheets(1)
tgt.name = name
src.Range("A" & Start & ":N" & Last).Copy
tgt.Range("A1:N" & Last).PasteSpecial xlPasteAll
wb.SaveAs name
wb.Close
End Sub