Copy sheet with popup message asking to name the new copied sheet

polska2180

Active Member
Joined
Oct 1, 2004
Messages
345
Hi, I have a master sheet I want to be able to copy by pressing a button then getting a popup asking what name I the user wants to name the sheet and then use that to name the sheet.

Thanks.
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,281
So you want to copy a sheet named "Master".
And then you want a Inputbox to Popup asking what name to give the new sheet is that what you want?
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,281
Try this:
Code:
Sub Copy_Master()
'Modified 6/12/2019 12:24:16 AM  EDT
Application.ScreenUpdating = False
On Error GoTo M
Dim ans As String
ans = InputBox("The New sheet you want named", "Enter new sheet name")
Sheets("Master").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = ans
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox ans & "  Is not a proper sheet name or has already been used"
End Sub
 

polska2180

Active Member
Joined
Oct 1, 2004
Messages
345
Try this:
Code:
Sub Copy_Master()
'Modified 6/12/2019 12:24:16 AM  EDT
Application.ScreenUpdating = False
On Error GoTo M
Dim ans As String
ans = InputBox("The New sheet you want named", "Enter new sheet name")
Sheets("Master").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = ans
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox ans & "  Is not a proper sheet name or has already been used"
End Sub
That almost works but when using existing name I get the error but a new sheets still gets created ie Master (1)
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,281
So what do you want to happen?

We can automatically delete the sheet or just warn you and you can delete the sheet.
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,281
Try this:
Code:
Sub Copy_Master()
'Modified 6/12/2019 12:36:16 AM  EDT
Application.ScreenUpdating = False
On Error GoTo M
Dim ans As String
ans = InputBox("The New sheet you want named", "Enter new sheet name")
Sheets("Master").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = ans
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox ans & "  Is not a proper sheet name or has already been used"
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub
 

polska2180

Active Member
Joined
Oct 1, 2004
Messages
345
Try this:
Code:
Sub Copy_Master()
'Modified 6/12/2019 12:36:16 AM  EDT
Application.ScreenUpdating = False
On Error GoTo M
Dim ans As String
ans = InputBox("The New sheet you want named", "Enter new sheet name")
Sheets("Master").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = ans
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox ans & "  Is not a proper sheet name or has already been used"
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub
TY. Not a deal breaker but when i select the same name it doesn't give me the popup again just stops and I have to click the button again. Is there a way to make it so the popup comes back to enter a different name. Also any reason the new sheets formating would show up differently ie the rows do not have the same height as the original. Also when i press cancel it still gives me a popup that this name is already used.
 
Last edited:

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,281
Well we are copying the sheet so all the row heights should be the same.

As far as your new requests now about what if this happens or that happens then Please rewrite your original post and spell out in exact detail all your requirements and be very specific.
 

polska2180

Active Member
Joined
Oct 1, 2004
Messages
345
Thanks, you don't really think of all the nuances until there is code and you see all the different issues that pop up. I will rewrite.
 

Forum statistics

Threads
1,082,250
Messages
5,364,027
Members
400,774
Latest member
Goldi paul

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top