Create multiple sheets from master named from list

Andreavnn

New Member
Joined
Mar 3, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello.

I have a file that has a master sheet that is formatted for a specific use. I have a list of part names on another sheet, there are 930 different parts. I am needing help creating a new copy of the master for each different part within the same excel document. Each sheet needs to be named after a different part. Basically, I need a copy of the master sheet for each unique item in column A and cell B1 to be named after the sheet name itself.

1646313833521.png
All unique items in column A need their own copy of the master sheet and their sheets need to be named - then cell B1 on the new sheets need to reflect the name of the sheet.

Hope that makes sense. Thank you!
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try:
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim i As Long, v As Variant
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                Sheets("Master").Copy after:=Sheets(Sheets.Count)
                ActiveSheet.Name = v(i, 1)
                Range("B1") = v(i, 1)
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I am getting an error. It is creating a sheet, but can't seem to change the name.


1646318198794.png



It seems to also be making copies of other sheets too.

Here are my sheet order
1646318334664.png


The master sheet is my template. Any sheet with (H) is typically hidden from view. I have a button on the input form that "actives" the creation of the sheets and my part list is on Data(H) sheet.
 
Upvote 0
Try:
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim i As Long, v As Variant
    Sheets("Data").Visible = True
    v = Sheets("Data").Range("A2", Sheets("Data").Range("A" & Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                Sheets("Master Sheet").Copy after:=Sheets(Sheets.Count)
                ActiveSheet.Name = v(i, 1)
                Range("B1") = v(i, 1)
            End If
        Next i
    End With
    Sheets("Data").Visible = xlHidden
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
This worked! But I have run into an error.

I didn't get a screen grab of the error, but is was something about the name wasn't or was over 31 characters. The error was some sort of naming convention error. It stopped on line 70 which reads "050/075PLBLANK".

Additionally, is there a way to add check into the code that will skip sheet that are ready created? How it is I can only run it once, which would normally be fine, but it make is hard to test when it makes half the sheets and then stops from any error and I have to create another copy of the master file to try another test.

Thank you so much by way, saving me tons of time not having to make the sheets manually!
 
Upvote 0
This worked! But I have run into an error.

I didn't get a screen grab of the error, but is was something about the name wasn't or was over 31 characters. The error was some sort of naming convention error. It stopped on line 70 which reads "050/075PLBLANK".

Additionally, is there a way to add check into the code that will skip sheet that are ready created? How it is I can only run it once, which would normally be fine, but it make is hard to test when it makes half the sheets and then stops from any error and I have to create another copy of the master file to try another test.

Thank you so much by way, saving me tons of time not having to make the sheets manually!
Here is the error

1646322053794.png
 
Upvote 0
I've figured it has to deal with the '/' in the name. There are a handful of items with a slash in their name. It looks like it can be removed and just replaced with a space which should work for the sheet name, but not the part name in B1. Not sure if there is a work around to be had here. :( Maybe it can skip part names with a slash and those can be created manually? I am open to suggestions on that part.

Sorry, for some many replies in a row. :(
 
Upvote 0
The length of sheet names cannot exceed 31 characters. This macro should address all your issues. If the sheet names contain "/", it will be replaced with a space and if the name is longer than 31 characters, it will be shortened to 31.
VBA Code:
Sub CreateSheets()
    Application.ScreenUpdating = False
    Dim i As Long, v As Variant, wsName As String
    Sheets("Data").Visible = True
    v = Sheets("Data").Range("A2", Sheets("Data").Range("A" & Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            wsName = Replace(Left(v(i, 1), 31), "/", " ")
            If Not .Exists(wsName) Then
                .Add wsName, Nothing
                If Not Evaluate("isref('" & wsName & "'!A1)") Then
                    Sheets("Master Sheet").Copy after:=Sheets(Sheets.Count)
                    ActiveSheet.Name = wsName
                    Range("B1") = wsName
                End If
            End If
        Next i
    End With
    Sheets("Data").Visible = xlHidden
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Working great. I am still running the code through for the first time so it is taking awhile, but so far no issues and it is all working. Thank you very much for helping and getting me pointed into the right direction with this.

Thank you! 10/10
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top