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

polska2180

Active Member
Joined
Oct 1, 2004
Messages
384
Office Version
  1. 365
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.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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?
 
Upvote 0
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
 
Upvote 0
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)
 
Upvote 0
So what do you want to happen?

We can automatically delete the sheet or just warn you and you can delete the sheet.
 
Upvote 0
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
 
Upvote 0
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:
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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