Avatar of forever7
forever7
 asked on

Creating New Sheets based on list and template

Hello,

I am looking for an Excel solution.

If I have a base worksheet template (which can change), I need to create sheets identical to the template for a specific list.

Each sheet will be named according to the list and a cell in each of the sheets to be named according to the list also.

The attached file is what I am looking for. For example, sheets will be generated (based on "BASE" template) and named according to column "D" and each sheet will have a named cell according to column "E".

When finished, the list would need to be deleted and just the sheets remaining.

Example excel attached.

thanks in advance
test_newsheet.xlsx
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
forever7

8/22/2022 - Mon
Wayne Taylor (webtubbs)

Try this macro...

Sub CreateSheets()

    Dim tmpSheet As Worksheet, lstSheet As Worksheet
    Dim rw As Long
    
    Set tmpSheet = Worksheets("BASE")
    Set lstSheet = Worksheets("LIST")
    
    For rw = 4 To lstSheet.Cells(Rows.Count, "D").End(xlUp).Row
        tmpSheet.Copy After:=Worksheets(Worksheets.Count)
        With ActiveSheet
            .Name = lstSheet.Cells(rw, "D")
            .Range("E1").Value = lstSheet.Cells(rw, "E")
        End With
    Next
    Application.DisplayAlerts = False
    lstSheet.Delete
    Application.DisplayAlerts = True
End Sub

Open in new window

forever7

ASKER
Thank You Wayne,

If I want to keep the main sheet, what would the edited code be?

Also, to delete the code if the workbook gets passed on do you open VB editor and delete "module 1" (if that's what I saved it as).

thanks
Wayne Taylor (webtubbs)

If I want to keep the main sheet, what would the edited code be?

To not delete the LIST sheet, remove lines 16-18.

Also, to delete the code if the workbook gets passed on do you open VB editor and delete "module 1" (if that's what I saved it as).

Yes, or you can save it as ".xlsx" which is a macro free workbook.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
forever7

ASKER
Thanks - this is just what I need.

one last thing if possible

If the sheets are required to have a different name, is there a way to rename the sheets that have been created with another name based on another column say "E".

For example, London No1, London No2... need to be renamed to Lon No1, Lon No2 etc..

This may occur after populating the created sheets with data?
forever7

ASKER
should have said ...another column say "F".
Wayne Taylor (webtubbs)

You can use the below macro to rename the sheets based on the values in column "F" on the LIST sheet...

Sub RenameSheets()

    Dim lstSheet As Worksheet, ws As Worksheet, rw As Long
    
    Set lstSheet = Worksheets("LIST")
    
    For rw = 4 To lstSheet.Cells(Rows.Count, "D").End(xlUp).Row
        On Error Resume Next
        Set ws = Worksheets(lstSheet.Cells(rw, "D").Value)
        If Not ws Is Nothing Then
            ws.Name = lstSheet.Cells(rw, "F")
        End If
        On Error GoTo 0
    Next
    
End Sub

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
forever7

ASKER
The rename works, but if I want to rename again to  something else, is there a way to rename a sheet to another sheet based on the list.

for example, I tried  renaming again by but it renamed in different order (it renamed the LIST and BASE tabs)?
forever7

ASKER
I may need to generate around 30-40 sheets. This a great help but if I can get the renaming correct then I can generate sheets, rename them if asked. and possibly rename again if things change.
ASKER CERTIFIED SOLUTION
Wayne Taylor (webtubbs)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
forever7

ASKER
Wayne - thanks very much - this is exactly what I needed. Great help.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23