Forum Discussion

cre8v1's avatar
cre8v1
Copper Contributor
Jan 08, 2020
Solved

Macro for adding named sheets in workbook from list

I am looking for a macro to add named sheets from a selected list to a workbook. Specifically, each sheet would have the same content duplicated from a template sheet, but named differently accordin...
  • Riny_van_Eekelen's avatar
    Jan 19, 2020

    cre8v1 

    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

     

     

Resources