Copy sheet multiple times and rename with user input

exsoil

New Member
Joined
Mar 29, 2022
Messages
3
Office Version
  1. 2021
  2. 2007
Platform
  1. Windows
Hello all,

I am trying to find a macro that allows me to copy my template sheet (JNH) multiple times but rename it based on a user input box. I can find macros that give input boxes to determine how many times to copy the template sheet and macros that give a user input box to rename a single sheet, but I cannot find a way to combine the two. My template sheet is "JNH". I want to copy the sheet, say, 5 times and have an input box pop up where I can type 5 custom names
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
Sub Maybe()
Dim i As Long, shName As String, a As String
a = ActiveSheet.Name
    For i = 1 To Application.InputBox("How many copies?", "Making Copies", 1, , , , 1)
        shName = Application.InputBox("Name of copy #" & i, "Naming Sheet", , , , , 2)
            Application.ScreenUpdating = False
                Sheets("JNH").Copy After:=Sheets(Sheets.Count)
                    ActiveSheet.Name = shName
                Sheets(a).Select
            Application.ScreenUpdating = True
    Next i
End Sub
 
Upvote 0
Another possibility if you want.
Enter names separated by a comma and sheets will be added by that amount.
Code:
Sub Maybe_2()
Dim i As Long, shName As String, a As String, nameArr
a = ActiveSheet.Name
shName = Application.InputBox("Enter all names separated by comma.", "Names For Sheets", , , , , 2)
Application.ScreenUpdating = False
nameArr = Split(shName, ",")
    For i = LBound(nameArr) To UBound(nameArr)
        Sheets("JNH").Copy After:=Sheets(Sheets.Count)
        ActiveSheet.Name = Trim(nameArr(i))
    Next i
Sheets(a).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Another possibility if you want.
Enter names separated by a comma and sheets will be added by that amount.
Code:
Sub Maybe_2()
Dim i As Long, shName As String, a As String, nameArr
a = ActiveSheet.Name
shName = Application.InputBox("Enter all names separated by comma.", "Names For Sheets", , , , , 2)
Application.ScreenUpdating = False
nameArr = Split(shName, ",")
    For i = LBound(nameArr) To UBound(nameArr)
        Sheets("JNH").Copy After:=Sheets(Sheets.Count)
        ActiveSheet.Name = Trim(nameArr(i))
    Next i
Sheets(a).Select
Application.ScreenUpdating = True
End Sub
Thanks so much Jolivanes!!
This VBA business is over my head but both of your solutions worked perfectly!! I think the comma separated one is my pick. Again, much appreciation!
 
Upvote 0
Perseverance will get you there.
Thanks for letting us know and good luck.
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,953
Members
449,198
Latest member
MhammadishaqKhan

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