Forum Discussion
Macro for adding named sheets in workbook from list
- Jan 19, 2020
I believe your question is to add worksheets (copied from a template) into a workbook based on a list, rather than list all the worksheets in the workbook.
The attached file has a working example, which includes the following short and easy to adapt (to your own situation) piece of code:
Sub AddSheets() Dim SheetList As Object Dim i As Integer Dim SheetName As String Set SheetList = ThisWorkbook.Sheets("SheetsToAdd").Range("A1").CurrentRegion For i = 1 To SheetList.Rows.Count SheetName = SheetList.Cells(i, 1) Sheets("Template").Select Sheets("Template").Copy After:=Sheets(Sheets.Count) ActiveSheet.Name = SheetName Next i End Sub
I believe your question is to add worksheets (copied from a template) into a workbook based on a list, rather than list all the worksheets in the workbook.
The attached file has a working example, which includes the following short and easy to adapt (to your own situation) piece of code:
Sub AddSheets()
Dim SheetList As Object
Dim i As Integer
Dim SheetName As String
Set SheetList = ThisWorkbook.Sheets("SheetsToAdd").Range("A1").CurrentRegion
For i = 1 To SheetList.Rows.Count
SheetName = SheetList.Cells(i, 1)
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = SheetName
Next i
End Sub
Riny_van_Eekelen Thank you for your response, this is exactly what I was looking for! I knew it would be simple, but didn't know exactly how to write the script. This will make it sooooo easy to create new spreadsheets for each date needed!