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.
 
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.

Specifically what I want is to copy a master sheet that includes...

1. a pop up asking for a new name
2. if duplicate provide a pop up stating so and a new pop up shows up to enter a name again.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
This is beyond my knowledgebase.

Your asking for the script to completely start over again with no interaction from you.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Well maybe I do know how:

Try this:
Code:
Sub Copy_Master()
'Modified  6/12/2019  1:45:38 AM  EDT
Application.ScreenUpdating = False
G:
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
GoTo G
End Sub
 
Upvote 0
This is beyond my knowledgebase.

Your asking for the script to completely start over again with no interaction from you.
I will continue to monitor this thread to see what I can learn.

I appreciate your help and quick responses it is not my intent to frustrate you not sure what exactly what you are looking for since I cannot foresee what the code will do and look like until i can actually try it out.

after I get a popup if I leave the box blank i get

MsgBox ans & " Is not a proper sheet name or has already been used"

and all dialog boxes go away so I have to press the button again...if I press cancel again I get the message

MsgBox ans & " Is not a proper sheet name or has already been used"

and after pressing ok all dialog boxes go away.

Typically when you leave a box blank you either get the dialog box flash or you get another massage like cannot be empty you press okay and it takes you back to the same box that where you enter the name. On the flip side if you press cancel you shouldn't get the error message but just simply have the process stopped.
 
Upvote 0
Well maybe I do know how:

Try this:
Code:
Sub Copy_Master()
'Modified  6/12/2019  1:45:38 AM  EDT
Application.ScreenUpdating = False
G:
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
GoTo G
End Sub
This creates issues...as after okay on blank or cancel it tries to delete activesheet. Also still gives a popup when you press cancel or okay on blank with this MsgBox ans & " Is not a proper sheet name or has already been used"
 
Upvote 0
That is because if you do not enter anything or click cancel you have not entered a proper sheet name.

The warning says you have entered a improper name or have already used that name.

So what's the problem?
 
Upvote 0
That is because if you do not enter anything or click cancel you have not entered a proper sheet name.

The warning says you have entered a improper name or have already used that name.

So what's the problem?

Little hard to comment as I am not knowledgeable enough to write the code but the problem is that if you press cancel you wouldn't typically expect to get an error similarly if you press ok without entering a name and get a debug error that will not work well when taking the end user into consideration.
 
Upvote 0
Try this:
The user will get no warning.

He will now know nothing happened when he entered a Improper name or a previously entered name.
All he will know is nothing happened:

Code:
Sub Copy_Master()
'Modified  6/12/2019  2:25:42 PM  EDT
Application.ScreenUpdating = False
G:
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:
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
GoTo G
End Sub
 
Last edited:
Upvote 0
After testing my last script I find it will not work.

I really have no answer for you.

Your wanting if the user enters a improper name or no value or clicks Cancel button to get no warning but just try again. If I were a user I would wonder why is this script just running over and over. I'm not sure what I'm doing wrong.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,620
Latest member
dsubash

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