VBA Modification to Rename sheet

jondavis1987

Active Member
Joined
Dec 31, 2015
Messages
443
Office Version
  1. 2019
Platform
  1. Windows
I have a vba code to make an identical worksheet of a template and delete the option button I use to activate it. Is there a way to have a dialogue box or something pop up where I could rename the sheet and then end the vba? It's not really a big deal for me but this is a shared file and sometimes when the other people sharing it use this template in that way they don't rename the copy to the what it should be. The name will always be unique so there's nowhere to put a value to make the name be referenced.

VBA Code:
Sub New_Superpave2()
    Sheets("Superpave Template").Copy After:=ActiveSheet
    Sheets("Superpave Template (2)").Select
    ActiveSheet.Shapes.Range(Array("Option Button 2")).Select
    Selection.Delete
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
NVM I just figured it out.

VBA Code:
Sub New_Superpave2()
    Sheets("Superpave Template").Copy After:=ActiveSheet
    Sheets("Superpave Template (2)").Select
    ActiveSheet.Shapes.Range(Array("Option Button 2")).Select
    Selection.Delete

response = InputBox("Name of the Sheet?", vbOKCancel)
If response = False Or response = "" Then
MsgBox "Invalid Name"
Exit Sub
Else
ActiveSheet.Name = response
End If
response = ""
End Sub
 
Upvote 0
A more compact version:
VBA Code:
Sub New_Superpave2()
    Sheets("Superpave Template").Copy After:=ActiveSheet
    ActiveSheet.Shapes.Range(Array("Option Button 2")).Select
    Selection.Delete
    On Error Resume Next
    ActiveSheet.Name = InputBox("Enter a valid name for the copied sheet")
End Sub
 
Upvote 0
A more compact version:
VBA Code:
Sub New_Superpave2()
    Sheets("Superpave Template").Copy After:=ActiveSheet
    ActiveSheet.Shapes.Range(Array("Option Button 2")).Select
    Selection.Delete
    On Error Resume Next
    ActiveSheet.Name = InputBox("Enter a valid name for the copied sheet")
End Sub
That works great and looks much cleaner. Still getting the hang of the VBA.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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