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

polska2180

Active Member
Joined
Oct 1, 2004
Messages
344
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,033
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,033
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
344
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,033
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,033
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
344
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,033
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
344
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,077,677
Messages
5,335,618
Members
399,029
Latest member
JSO

Some videos you may like

This Week's Hot Topics

Top